Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed May 1, 2024
1 parent dc15455 commit 7f6c1f0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ class DiskStore extends AbstractStore<DiskStore> {
this.blockNumber = new AtomicInteger(0);
}

/**
* Creates a clone of the given store.
*
* @param toClone the store to clone
*/
private DiskStore(DiskStore toClone) {
this.dir = toClone.dir;
this.histories = toClone.histories;
this.errors = toClone.errors;
this.manifest = toClone.manifest;
this.blockNumber = toClone.blockNumber;
}

@Override
public Optional<TransactionResponse> getResponse(TransactionReference reference) {
try {
Expand Down Expand Up @@ -158,16 +145,6 @@ public StoreTransaction<DiskStore> beginTransaction() {
return new DiskStoreTransaction(this);
}

@Override
protected DiskStore getThis() {
return this;
}

@Override
protected DiskStore mkClone() {
return new DiskStore(this);
}

protected void setRequest(int progressive, TransactionReference reference, TransactionRequest<?> request) throws StoreException {
try {
Path requestPath = getPathFor(progressive, reference, "request");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.hotmoka.stores.StoreException;

public class DiskStoreTransaction extends AbstractStoreTransaction<DiskStore> {
private final DiskStore store;
private final ConcurrentMap<TransactionReference, TransactionRequest<?>> requests = new ConcurrentHashMap<>();
private final ConcurrentMap<TransactionReference, TransactionResponse> responses = new ConcurrentHashMap<>();

Expand All @@ -36,7 +35,7 @@ public class DiskStoreTransaction extends AbstractStoreTransaction<DiskStore> {
private final AtomicReference<StorageReference> manifest = new AtomicReference<>();

public DiskStoreTransaction(DiskStore store) {
this.store = store;
super(store);
}

@Override
Expand All @@ -45,7 +44,7 @@ public Optional<TransactionResponse> getResponseUncommitted(TransactionReference
if (uncommittedResponse != null)
return Optional.of(uncommittedResponse);
else
return store.getResponse(reference);
return getStore().getResponse(reference);
}

@Override
Expand All @@ -54,7 +53,7 @@ public Stream<TransactionReference> getHistoryUncommitted(StorageReference objec
if (uncommittedHistory != null)
return Stream.of(uncommittedHistory);
else
return store.getHistory(object);
return getStore().getHistory(object);
}

@Override
Expand All @@ -63,11 +62,13 @@ public Optional<StorageReference> getManifestUncommitted() {
if (uncommittedManifest != null)
return Optional.of(uncommittedManifest);
else
return store.getManifest();
return getStore().getManifest();
}

@Override
public DiskStore commit() throws StoreException {
var store = getStore();

// we report all the updates occurred during this transaction into the store
var manifest = this.manifest.get();
if (manifest != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ public class TendermintStore extends AbstractTrieBasedStore<TendermintStore> {
}
}

private TendermintStore(TendermintStore toClone) {
super(toClone);

this.nodeInternal = toClone.nodeInternal;
this.hasherOfHashes = toClone.hasherOfHashes;
}

private TendermintStore(TendermintStore toClone, Optional<byte[]> rootOfResponses, Optional<byte[]> rootOfInfo, Optional<byte[]> rootOfErrors, Optional<byte[]> rootOfHistories, Optional<byte[]> rootOfRequests) {
super(toClone, rootOfResponses, rootOfInfo, rootOfErrors, rootOfHistories, rootOfRequests);

Expand Down Expand Up @@ -130,16 +123,6 @@ private byte[] mergeRootsOfTriesWithoutInfo() throws StoreException {
return bytes;
}

@Override
protected TendermintStore getThis() {
return this;
}

@Override
protected TendermintStore mkClone() {
return new TendermintStore(this);
}

@Override
protected TendermintStore mkClone(Optional<byte[]> rootOfResponses, Optional<byte[]> rootOfInfo, Optional<byte[]> rootOfErrors, Optional<byte[]> rootOfHistories, Optional<byte[]> rootOfRequests) {
return new TendermintStore(this, rootOfResponses, rootOfInfo, rootOfErrors, rootOfHistories, rootOfRequests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public abstract class AbstractStore<T extends AbstractStore<T>> implements Store
*/
protected AbstractStore() {}

protected abstract T mkClone();

protected abstract T getThis();

@Override
public void close() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@
*/
public abstract class AbstractStoreTransaction<T extends Store<T>> implements StoreTransaction<T> {
private final static Logger LOGGER = Logger.getLogger(AbstractStoreTransaction.class.getName());
private final T store;

protected AbstractStoreTransaction() {}
protected AbstractStoreTransaction(T store) {
this.store = store;
}

protected final T getStore() {
return store;
}

@Override
public final void push(TransactionReference reference, TransactionRequest<?> request, TransactionResponse response) throws StoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public abstract class AbstractTrieBasedStoreTransaction<T extends AbstractTrieBa
*/
private final Transaction txn;

/**
* The store from which this transaction was started.
*/
private final T store;

/**
* The trie of the responses.
*/
Expand All @@ -53,8 +48,9 @@ public abstract class AbstractTrieBasedStoreTransaction<T extends AbstractTrieBa
private volatile TrieOfRequests trieOfRequests;

protected AbstractTrieBasedStoreTransaction(T store, Transaction txn) throws StoreException {
super(store);

this.txn = txn;
this.store = store;
this.trieOfResponses = store.mkTrieOfResponses(txn);
this.trieOfInfo = store.mkTrieOfInfo(txn);
this.trieOfErrors = store.mkTrieOfErrors(txn);
Expand Down Expand Up @@ -154,7 +150,7 @@ public T commit() throws StoreException {
if (!txn.commit())
throw new StoreException("Cannot commit the Xodus transaction");

return store.mkClone(
return getStore().mkClone(
Optional.of(trieOfResponses.getRoot()),
Optional.of(trieOfInfo.getRoot()),
Optional.of(trieOfErrors.getRoot()),
Expand Down

0 comments on commit 7f6c1f0

Please sign in to comment.