*/
public abstract class AbstractReplicatedLogImpl implements ReplicatedLog {
- protected List<ReplicatedLogEntry> journal;
+ // We define this as ArrayList so we can use ensureCapacity.
+ protected ArrayList<ReplicatedLogEntry> journal;
protected ByteString snapshot;
protected long snapshotIndex = -1;
protected long snapshotTerm = -1;
// to be used for rollback during save snapshot failure
- protected List<ReplicatedLogEntry> snapshottedJournal;
+ protected ArrayList<ReplicatedLogEntry> snapshottedJournal;
protected ByteString previousSnapshot;
protected long previousSnapshotIndex = -1;
protected long previousSnapshotTerm = -1;
journal.add(replicatedLogEntry);
}
+ @Override
+ public void increaseJournalLogCapacity(int amount) {
+ journal.ensureCapacity(journal.size() + amount);
+ }
+
@Override
public List<ReplicatedLogEntry> getFrom(long logEntryIndex) {
return getFrom(logEntryIndex, journal.size());
@Override
public void snapshotCommit() {
- snapshottedJournal.clear();
snapshottedJournal = null;
previousSnapshotIndex = -1;
previousSnapshotTerm = -1;
@Override
public void snapshotRollback() {
snapshottedJournal.addAll(journal);
- journal.clear();
journal = snapshottedJournal;
snapshottedJournal = null;