Skip to content

Commit

Permalink
Ensure Repository is saved even when no transactions took place
Browse files Browse the repository at this point in the history
Previously if stores had been deleted but were pending purge at shutdown
(e.g. in the event of abnormal termination), and then the database was
shutdown without any transactions having been committed, then the
stores would be purged, but that state change would not be reflected
in the persisted Repository instance.

Also spotted an off by one error in this area.
  • Loading branch information
nealeu committed Nov 20, 2012
1 parent 1df7a2c commit 905f6d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ public void shutdown() {
pager.saveAll();

repository.purgeDeletedStores();

if (latestDiskVersion != repository.getVersion()) {
repository.save(setup.getReposDiskRoot());
}
// always save on shutdown (we may have deleted stores, even if we've not processed
// any transactions, hence will have modified Repository
repository.save(setup.getReposDiskRoot());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,6 @@ public void initialise() {
for (ServerStore store : idStoreMap.values()) {
store.initialise();
}
synchronized (deletedStoresByVersion) {
for (ArrayList<Integer> als : deletedStoresByVersion.values()) {
for (Integer storeId : als) {
ServerStore store = idStoreMap.get(storeId);
store.initialise();
}
}
}
}

public void upissue() {
Expand Down Expand Up @@ -385,13 +377,19 @@ public void purgeDeletedStores(long oldestTransaction) {

while (i.hasNext()) {
Entry<Long, ArrayList<Integer>> versionEntry = i.next();
if (versionEntry.getKey() > oldestTransaction) {
if (versionEntry.getKey() >= oldestTransaction) {
continue; // these are still live
}

// These are expired so add the to our expiredList, and remove from here.
for (Integer id : versionEntry.getValue()) {
expiredStores.add(idStoreMap.get(id));
ServerStore store = idStoreMap.get(id);
if (store != null) {
expiredStores.add(store);
}
else {
log.warn("Store {} had already been deleted from disk", id);
}
idStoreMap.remove(id);
}
i.remove(); // removes entire array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void createStore() throws IOException {
public void deleteStore() {

try {
if (client != null |client.isConnected()) {
if (client != null && client.isConnected()) {
client.deleteStore(storeName);
}
} catch (UnknownStoreException e) {
Expand Down

0 comments on commit 905f6d2

Please sign in to comment.