forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8b7913
commit 15d13a2
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ava/org/opensearch/index/store/remote/file/RefTrackedOnDemandBlockSnapshotIndexInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.store.remote.file; | ||
|
||
import org.apache.lucene.store.IndexInput; | ||
import org.apache.lucene.store.FSDirectory; | ||
import org.opensearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot; | ||
import org.opensearch.index.store.remote.utils.TransferManager; | ||
|
||
import java.io.IOException; | ||
import java.lang.ref.WeakReference; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Maintains a list of weak references to all clones. On close ensure all clones are closed as well. | ||
* Per {@link IndexInput} cloned IndexInputs can be closed with the parent. | ||
*/ | ||
public class RefTrackedOnDemandBlockSnapshotIndexInput extends OnDemandBlockSnapshotIndexInput { | ||
|
||
private final ArrayList<WeakReference<IndexInput>> cloneRefs; | ||
|
||
public RefTrackedOnDemandBlockSnapshotIndexInput(OnDemandBlockSnapshotIndexInput parentObject, ArrayList<WeakReference<IndexInput>> parentRefList) { | ||
super(parentObject); | ||
this.cloneRefs = parentRefList; | ||
} | ||
|
||
public RefTrackedOnDemandBlockSnapshotIndexInput(BlobStoreIndexShardSnapshot.FileInfo fileInfo, FSDirectory directory, TransferManager transferManager) { | ||
super(fileInfo, directory, transferManager); | ||
this.cloneRefs = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public RefTrackedOnDemandBlockSnapshotIndexInput clone() { | ||
RefTrackedOnDemandBlockSnapshotIndexInput retClone = new RefTrackedOnDemandBlockSnapshotIndexInput(super.clone(), cloneRefs); | ||
cloneRefs.add(new WeakReference<>(retClone)); | ||
return retClone; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (!isClone) { | ||
for (WeakReference<IndexInput> ref : cloneRefs) { | ||
IndexInput input = ref.get(); | ||
if (input != null) { | ||
System.out.println("CLOSING AN UNCLOSED REF: " + input); | ||
|
||
// input.close(); | ||
} | ||
|
||
System.out.println("NO CLOSE - REF ALREADY NULL: " + input); | ||
|
||
// cloneRefs.remove(ref); // For now don't remove for debugging | ||
} | ||
} | ||
super.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters