forked from kptfh/nosql-batch-updater
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWriteAheadLogCompleter.java
56 lines (46 loc) · 2.12 KB
/
WriteAheadLogCompleter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package nosql.batch.update.wal;
import nosql.batch.update.BatchOperations;
import nosql.batch.update.lock.Lock;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
/**
* Completes hanged transactions
*/
public class WriteAheadLogCompleter<LOCKS, UPDATES, L extends Lock, BATCH_ID>
extends AbstractWriteAheadLogCompleter<LOCKS, UPDATES, BATCH_ID>{
private final WriteAheadLogManager<LOCKS, UPDATES, BATCH_ID> writeAheadLogManager;
private final BatchOperations<LOCKS, UPDATES, L, BATCH_ID> batchOperations;
/**
* @param batchOperations
* @param staleBatchesThreshold
* @param exclusiveLocker
* @param scheduledExecutorService
*/
public WriteAheadLogCompleter(BatchOperations<LOCKS, UPDATES, L, BATCH_ID> batchOperations,
Duration staleBatchesThreshold,
int batchSize,
ExclusiveLocker exclusiveLocker, ScheduledExecutorService scheduledExecutorService){
super(staleBatchesThreshold, batchSize, exclusiveLocker, scheduledExecutorService);
this.writeAheadLogManager = batchOperations.getWriteAheadLogManager();
this.batchOperations = batchOperations;
}
@Override
protected void releaseLocksAndDeleteWalTransactionOnError(WalRecord<LOCKS, UPDATES, BATCH_ID> batch) {
batchOperations.releaseLocksAndDeleteWalTransactionOnError(
batch.batchUpdate.locks(), batch.batchId);
}
@Override
protected void processAndDeleteTransactions(WalRecord<LOCKS, UPDATES, BATCH_ID> batch) {
batchOperations.processAndDeleteTransaction(
batch.batchId, batch.batchUpdate, true);
}
@Override
protected List<WalTimeRange> getTimeRanges(Duration staleBatchesThreshold, int batchSize) {
return writeAheadLogManager.getTimeRanges(staleBatchesThreshold, batchSize);
}
@Override
protected List<WalRecord<LOCKS, UPDATES, BATCH_ID>> getStaleBatchesForRange(WalTimeRange timeRange) {
return writeAheadLogManager.getStaleBatchesForRange(timeRange);
}
}