File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
main/java/org/elasticsearch/index/translog
test/java/org/elasticsearch/index/translog Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -1428,7 +1428,23 @@ public void prepareCommit() throws IOException {
14281428 public void commit (final long committedGeneration ) throws IOException {
14291429 try (ReleasableLock ignored = writeLock .acquire ()) {
14301430 ensureOpen ();
1431- assert committedGeneration <= current .generation ;
1431+ if (committedGeneration > current .generation ) {
1432+ final String message = String .format (
1433+ Locale .ROOT ,
1434+ "tried to commit generation [%d] later than the current generation [%d]" ,
1435+ committedGeneration ,
1436+ current .generation );
1437+ throw new IllegalStateException (message );
1438+ }
1439+ final Long min = readers .stream ().map (TranslogReader ::getGeneration ).min (Long ::compareTo ).orElse (Long .MIN_VALUE );
1440+ if (committedGeneration < min ) {
1441+ final String message = String .format (
1442+ Locale .ROOT ,
1443+ "tried to commit generation [%d] before minimum generation [%d]" ,
1444+ committedGeneration ,
1445+ min );
1446+ throw new IllegalStateException (message );
1447+ }
14321448 if (currentCommittingGeneration == NOT_SET_GENERATION ) {
14331449 prepareCommit ();
14341450 }
Original file line number Diff line number Diff line change @@ -2249,6 +2249,7 @@ public void testSimpleCommit() throws IOException {
22492249 public void testPrepareCommitAndCommit () throws IOException {
22502250 final int operations = randomIntBetween (1 , 4096 );
22512251 long seqNo = 0 ;
2252+ long last = -1 ;
22522253 for (int i = 0 ; i < operations ; i ++) {
22532254 translog .add (new Translog .NoOp (seqNo ++, 0 , "test" ));
22542255 if (rarely ()) {
@@ -2258,7 +2259,9 @@ public void testPrepareCommitAndCommit() throws IOException {
22582259 // simulate generation filling up and rolling between preparing the commit and committing
22592260 translog .rollGeneration ();
22602261 }
2261- translog .commit (randomIntBetween (1 , Math .toIntExact (generation )));
2262+ final int committedGeneration = randomIntBetween (Math .max (1 , Math .toIntExact (last )), Math .toIntExact (generation ));
2263+ translog .commit (committedGeneration );
2264+ last = committedGeneration ;
22622265 for (long g = 0 ; i < generation ; g ++) {
22632266 assertFileDeleted (translog , g );
22642267 }
You can’t perform that action at this time.
0 commit comments