The Unified and Autonomous Development Platform
Xodus not closing mode
robin shinea28ed38d8ba8
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.javaindex 8d415fa5b8..5e35093605 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAuxiliaryManager.java@@ -23,7 +23,6 @@ import com.pmease.commons.git.Git;import com.pmease.commons.git.command.CommitConsumer;import com.pmease.commons.git.command.LogCommand;import com.pmease.commons.util.FileUtils;-import com.pmease.commons.util.ObjectReference;import com.pmease.gitplex.core.listeners.RepositoryListener;import com.pmease.gitplex.core.manager.AuxiliaryManager;import com.pmease.gitplex.core.manager.SequentialWorkManager;@@ -53,7 +52,7 @@ public class DefaultAuxiliaryManager implements AuxiliaryManager, RepositoryListprivate final SequentialWorkManager sequentialWorkManager;- private final Map<Long, ObjectReference<Environment>> envRefs = new HashMap<>();+ private final Map<Long, Environment> envs = new HashMap<>();@Injectpublic DefaultAuxiliaryManager(StorageManager storageManager, WorkManager workManager,@@ -75,55 +74,49 @@ public class DefaultAuxiliaryManager implements AuxiliaryManager, RepositoryList@Overridepublic void run() {- executeInEnv(repository, new EnvExecutable() {-+ Environment env = getEnv(repository);+ final Store lastCommitStore = getStore(env, "lastCommit");+ final Store commitsStore = getStore(env, "commits");+ env.executeInTransaction(new TransactionalExecutable() {+@Override- public void execute(Environment env) {- final Store lastCommitStore = getStore(env, "lastCommit");- final Store commitsStore = getStore(env, "commits");- env.executeInTransaction(new TransactionalExecutable() {-- @Override- public void execute(final Transaction txn) {- ByteIterable lastCommitKey = new StringByteIterable("lastCommit");- byte[] value = getBytes(lastCommitStore.get(txn, lastCommitKey));- String lastCommit = value!=null?new String(value):null;- Git git = repository.git();- final AtomicLong count = new AtomicLong(0);+ public void execute(final Transaction txn) {+ ByteIterable lastCommitKey = new StringByteIterable("lastCommit");+ byte[] value = getBytes(lastCommitStore.get(txn, lastCommitKey));+ String lastCommit = value!=null?new String(value):null;+ Git git = repository.git();+ final AtomicLong count = new AtomicLong(0);++ LogCommand log = new LogCommand(git.repoDir());+ List<String> revisions = new ArrayList<>();+ if (lastCommit != null)+ revisions.add(lastCommit + ".." + refName);+ else+ revisions.add(refName);++ final AtomicReference<Commit> lastCommitRef = new AtomicReference<>(null);+ log.revisions(revisions).listChangedFiles(true).run(new CommitConsumer() {- LogCommand log = new LogCommand(git.repoDir());- List<String> revisions = new ArrayList<>();- if (lastCommit != null)- revisions.add(lastCommit + ".." + refName);- else- revisions.add(refName);-- final AtomicReference<Commit> lastCommitRef = new AtomicReference<>(null);- log.revisions(revisions).listChangedFiles(true).run(new CommitConsumer() {-- @Override- public void consume(Commit commit) {- ByteIterable key = new StringByteIterable(commit.getHash());- if (commitsStore.get(txn, key) == null) {- byte[] commitBytes = SerializationUtils.serialize(commit);- commitsStore.put(txn, key, new ArrayByteIterable(commitBytes));- }- if (count.incrementAndGet() % 100 == 0)- txn.flush();- if (lastCommitRef.get() == null)- lastCommitRef.set(commit);- }-- });-- if (lastCommitRef.get() != null) {- value = lastCommitRef.get().getHash().getBytes();- lastCommitStore.put(txn, lastCommitKey, new ArrayByteIterable(value));+ @Override+ public void consume(Commit commit) {+ ByteIterable key = new StringByteIterable(commit.getHash());+ if (commitsStore.get(txn, key) == null) {+ byte[] commitBytes = SerializationUtils.serialize(commit);+ commitsStore.put(txn, key, new ArrayByteIterable(commitBytes));}+ if (count.incrementAndGet() % 100 == 0)+ txn.flush();+ if (lastCommitRef.get() == null)+ lastCommitRef.set(commit);}+});++ if (lastCommitRef.get() != null) {+ value = lastCommitRef.get().getHash().getBytes();+ lastCommitStore.put(txn, lastCommitKey, new ArrayByteIterable(value));+ }}-});}@@ -136,47 +129,15 @@ public class DefaultAuxiliaryManager implements AuxiliaryManager, RepositoryList});}- private void executeInEnv(Repository repository, EnvExecutable executable) {- ObjectReference<Environment> ref = getEnvRef(repository);- Environment env = ref.open();- try {- executable.execute(env);- } finally {- ref.close();- }- }-- private <T> T computeInEnv(Repository repository, EnvComputable<T> computable) {- ObjectReference<Environment> ref = getEnvRef(repository);- Environment env = ref.open();- try {- return computable.compute(env);- } finally {- ref.close();- }- }-- private synchronized ObjectReference<Environment> getEnvRef(final Repository repository) {- ObjectReference<Environment> ref = envRefs.get(repository.getId());- if (ref == null) {- ref = new ObjectReference<Environment>() {-- @Override- protected Environment openObject() {- EnvironmentConfig config = new EnvironmentConfig();- config.setLogCacheShared(false);- return Environments.newInstance(getAuxiliaryDir(repository), config);- }-- @Override- protected void closeObject(Environment object) {- object.close();- }-- };- envRefs.put(repository.getId(), ref);+ private synchronized Environment getEnv(final Repository repository) {+ Environment env = envs.get(repository.getId());+ if (env == null) {+ EnvironmentConfig config = new EnvironmentConfig();+ config.setLogCacheShared(false);+ env = Environments.newInstance(getAuxiliaryDir(repository), config);+ envs.put(repository.getId(), env);}- return ref;+ return env;}private File getAuxiliaryDir(Repository repository) {@@ -197,27 +158,21 @@ public class DefaultAuxiliaryManager implements AuxiliaryManager, RepositoryList@Overridepublic Map<String, Commit> getCommits(final Repository repository, final Set<String> commitHashes) {- return computeInEnv(repository, new EnvComputable<Map<String, Commit>>() {+ Environment env = getEnv(repository);+ final Store commitsStore = getStore(env, "commits");- @Override- public Map<String, Commit> compute(Environment env) {- final Store commitsStore = getStore(env, "commits");-- return env.computeInReadonlyTransaction(new TransactionalComputable<Map<String, Commit>>() {+ return env.computeInReadonlyTransaction(new TransactionalComputable<Map<String, Commit>>() {- @Override- public Map<String, Commit> compute(Transaction txn) {- Map<String, Commit> commits = new HashMap<>();- for (String commitHash: commitHashes) {- byte[] value = getBytes(commitsStore.get(txn, new StringByteIterable(commitHash)));- if (value != null)- commits.put(commitHash, (Commit) SerializationUtils.deserialize(value));- }- return commits;- }- });+ @Override+ public Map<String, Commit> compute(Transaction txn) {+ Map<String, Commit> commits = new HashMap<>();+ for (String commitHash: commitHashes) {+ byte[] value = getBytes(commitsStore.get(txn, new StringByteIterable(commitHash)));+ if (value != null)+ commits.put(commitHash, (Commit) SerializationUtils.deserialize(value));+ }+ return commits;}-});}@@ -261,14 +216,6 @@ public class DefaultAuxiliaryManager implements AuxiliaryManager, RepositoryListreturn null;}- static interface EnvExecutable {- void execute(Environment env);- }-- static interface EnvComputable<T> {- T compute(Environment env);- }-static class StringByteIterable extends ArrayByteIterable {StringByteIterable(String value) {super(value.getBytes());