@@ -36,8 +36,8 @@ final class SoftDeletesPolicy {
3636 private final LongSupplier globalCheckpointSupplier ;
3737 private int retentionLockCount ;
3838 private long checkpointOfSafeCommit ;
39- private volatile long minRequiredSeqNoForRecovery ;
40- private volatile long retentionOperations ;
39+ private long minRequiredSeqNoForRecovery ;
40+ private long retentionOperations ;
4141
4242 SoftDeletesPolicy (LongSupplier globalCheckpointSupplier , long retentionOperations ) {
4343 this .globalCheckpointSupplier = globalCheckpointSupplier ;
@@ -51,7 +51,7 @@ final class SoftDeletesPolicy {
5151 * Updates the number of soft-deleted prior to the global checkpoint to be retained
5252 * See {@link org.elasticsearch.index.IndexSettings#INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING}
5353 */
54- void setRetentionOperations (long retentionOperations ) {
54+ synchronized void setRetentionOperations (long retentionOperations ) {
5555 this .retentionOperations = retentionOperations ;
5656 }
5757
@@ -82,8 +82,8 @@ private void updateMinRequiredSeqNoForRecovery() {
8282 * This is a analogy to the translog's retention lock; see {@link Translog#acquireRetentionLock()}
8383 */
8484 synchronized Releasable acquireRetentionLock () {
85+ assert retentionLockCount >= 0 : "Invalid number of retention locks [" + retentionLockCount + "]" ;
8586 retentionLockCount ++;
86- assert retentionLockCount > 0 : "Invalid number of retention locks [" + retentionLockCount + "]" ;
8787 final AtomicBoolean released = new AtomicBoolean ();
8888 return () -> {
8989 if (released .compareAndSet (false , true )) {
@@ -93,8 +93,8 @@ synchronized Releasable acquireRetentionLock() {
9393 }
9494
9595 private synchronized void releaseRetentionLock () {
96+ assert retentionLockCount > 0 : "Invalid number of retention locks [" + retentionLockCount + "]" ;
9697 retentionLockCount --;
97- assert retentionLockCount >= 0 : "Invalid number of retention locks [" + retentionLockCount + "]" ;
9898 updateMinRequiredSeqNoForRecovery ();
9999 }
100100
@@ -107,7 +107,7 @@ Query retentionQuery() {
107107 }
108108
109109 // Package-level for testing
110- long getMinSeqNoToRetain () {
110+ synchronized long getMinSeqNoToRetain () {
111111 final long minSeqNoForQueryingChanges = globalCheckpointSupplier .getAsLong () + 1 - retentionOperations ;
112112 return Math .min (minRequiredSeqNoForRecovery , minSeqNoForQueryingChanges );
113113 }
0 commit comments