51
51
import org .apache .lucene .util .SetOnce ;
52
52
import org .apache .lucene .util .ThreadInterruptedException ;
53
53
import org .opensearch .Assertions ;
54
+ import org .opensearch .ExceptionsHelper ;
54
55
import org .opensearch .LegacyESVersion ;
55
56
import org .opensearch .OpenSearchException ;
56
- import org .opensearch .ExceptionsHelper ;
57
57
import org .opensearch .action .ActionListener ;
58
58
import org .opensearch .action .ActionRunnable ;
59
59
import org .opensearch .action .admin .indices .flush .FlushRequest ;
73
73
import org .opensearch .common .CheckedRunnable ;
74
74
import org .opensearch .common .Nullable ;
75
75
import org .opensearch .common .collect .Tuple ;
76
+ import org .opensearch .common .concurrent .GatedCloseable ;
76
77
import org .opensearch .common .io .stream .BytesStreamOutput ;
77
78
import org .opensearch .common .lease .Releasable ;
78
79
import org .opensearch .common .lease .Releasables ;
@@ -1409,7 +1410,7 @@ public org.apache.lucene.util.Version minimumCompatibleVersion() {
1409
1410
*
1410
1411
* @param flushFirst <code>true</code> if the index should first be flushed to disk / a low level lucene commit should be executed
1411
1412
*/
1412
- public Engine . IndexCommitRef acquireLastIndexCommit (boolean flushFirst ) throws EngineException {
1413
+ public GatedCloseable < IndexCommit > acquireLastIndexCommit (boolean flushFirst ) throws EngineException {
1413
1414
final IndexShardState state = this .state ; // one time volatile read
1414
1415
// we allow snapshot on closed index shard, since we want to do one after we close the shard and before we close the engine
1415
1416
if (state == IndexShardState .STARTED || state == IndexShardState .CLOSED ) {
@@ -1423,7 +1424,7 @@ public Engine.IndexCommitRef acquireLastIndexCommit(boolean flushFirst) throws E
1423
1424
* Snapshots the most recent safe index commit from the currently running engine.
1424
1425
* All index files referenced by this index commit won't be freed until the commit/snapshot is closed.
1425
1426
*/
1426
- public Engine . IndexCommitRef acquireSafeIndexCommit () throws EngineException {
1427
+ public GatedCloseable < IndexCommit > acquireSafeIndexCommit () throws EngineException {
1427
1428
final IndexShardState state = this .state ; // one time volatile read
1428
1429
// we allow snapshot on closed index shard, since we want to do one after we close the shard and before we close the engine
1429
1430
if (state == IndexShardState .STARTED || state == IndexShardState .CLOSED ) {
@@ -1448,24 +1449,24 @@ public Engine.IndexCommitRef acquireSafeIndexCommit() throws EngineException {
1448
1449
*/
1449
1450
public Store .MetadataSnapshot snapshotStoreMetadata () throws IOException {
1450
1451
assert Thread .holdsLock (mutex ) == false : "snapshotting store metadata under mutex" ;
1451
- Engine . IndexCommitRef indexCommit = null ;
1452
+ GatedCloseable < IndexCommit > wrappedIndexCommit = null ;
1452
1453
store .incRef ();
1453
1454
try {
1454
1455
synchronized (engineMutex ) {
1455
1456
// if the engine is not running, we can access the store directly, but we need to make sure no one starts
1456
1457
// the engine on us. If the engine is running, we can get a snapshot via the deletion policy of the engine.
1457
1458
final Engine engine = getEngineOrNull ();
1458
1459
if (engine != null ) {
1459
- indexCommit = engine .acquireLastIndexCommit (false );
1460
+ wrappedIndexCommit = engine .acquireLastIndexCommit (false );
1460
1461
}
1461
- if (indexCommit == null ) {
1462
+ if (wrappedIndexCommit == null ) {
1462
1463
return store .getMetadata (null , true );
1463
1464
}
1464
1465
}
1465
- return store .getMetadata (indexCommit .get ());
1466
+ return store .getMetadata (wrappedIndexCommit .get ());
1466
1467
} finally {
1467
1468
store .decRef ();
1468
- IOUtils .close (indexCommit );
1469
+ IOUtils .close (wrappedIndexCommit );
1469
1470
}
1470
1471
}
1471
1472
@@ -3913,7 +3914,7 @@ void resetEngineToGlobalCheckpoint() throws IOException {
3913
3914
true
3914
3915
) {
3915
3916
@ Override
3916
- public IndexCommitRef acquireLastIndexCommit (boolean flushFirst ) {
3917
+ public GatedCloseable < IndexCommit > acquireLastIndexCommit (boolean flushFirst ) {
3917
3918
synchronized (engineMutex ) {
3918
3919
if (newEngineReference .get () == null ) {
3919
3920
throw new AlreadyClosedException ("engine was closed" );
@@ -3924,7 +3925,7 @@ public IndexCommitRef acquireLastIndexCommit(boolean flushFirst) {
3924
3925
}
3925
3926
3926
3927
@ Override
3927
- public IndexCommitRef acquireSafeIndexCommit () {
3928
+ public GatedCloseable < IndexCommit > acquireSafeIndexCommit () {
3928
3929
synchronized (engineMutex ) {
3929
3930
if (newEngineReference .get () == null ) {
3930
3931
throw new AlreadyClosedException ("engine was closed" );
0 commit comments