forked from infinispan/infinispan
-
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.
Prevent accidental deletion of files
- Loading branch information
anujshahwork
authored and
anujshahwork
committed
Aug 18, 2015
1 parent
e222c12
commit a31e93c
Showing
11 changed files
with
198 additions
and
26 deletions.
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
111 changes: 111 additions & 0 deletions
111
lucene/lucene-directory/src/main/java/org/infinispan/lucene/FileDeleteMarkerKey.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,111 @@ | ||
package org.infinispan.lucene; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
import java.util.Set; | ||
|
||
import org.infinispan.commons.marshall.AbstractExternalizer; | ||
import org.infinispan.commons.util.Util; | ||
|
||
/** | ||
* Lucene's index segment files are chunked, for safe deletion of elements a read lock is | ||
* implemented so that all chunks are deleted only after the usage counter is decremented to zero. | ||
* FileDeleteMarkerKey is used as a key for the reference counters; a special purpose key was needed to | ||
* make atomic operation possible. | ||
*/ | ||
public class FileDeleteMarkerKey implements IndexScopedKey { | ||
|
||
private final String indexName; | ||
private final String fileName; | ||
private final int hashCode; | ||
|
||
public FileDeleteMarkerKey(final String indexName, final String fileName) { | ||
if (indexName == null) | ||
throw new IllegalArgumentException("indexName shall not be null"); | ||
if (fileName == null) | ||
throw new IllegalArgumentException("fileName shall not be null"); | ||
this.indexName = indexName; | ||
this.fileName = fileName; | ||
this.hashCode = generateHashCode(); | ||
} | ||
|
||
/** | ||
* Get the indexName. | ||
* | ||
* @return the indexName. | ||
*/ | ||
@Override | ||
public String getIndexName() { | ||
return indexName; | ||
} | ||
|
||
/** | ||
* Get the fileName. | ||
* | ||
* @return the fileName. | ||
*/ | ||
public String getFileName() { | ||
return fileName; | ||
} | ||
|
||
@Override | ||
public Object accept(KeyVisitor visitor) throws Exception { | ||
return visitor.visit(this); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode; | ||
} | ||
|
||
private int generateHashCode() { | ||
final int prime = 31; | ||
int result = prime + fileName.hashCode(); | ||
return prime * result + indexName.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (FileDeleteMarkerKey.class != obj.getClass()) | ||
return false; | ||
FileDeleteMarkerKey other = (FileDeleteMarkerKey) obj; | ||
return fileName.equals(other.fileName) && indexName.equals(other.indexName); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return fileName + "|D|"+ indexName; | ||
} | ||
|
||
public static final class Externalizer extends AbstractExternalizer<FileDeleteMarkerKey> { | ||
|
||
@Override | ||
public void writeObject(final ObjectOutput output, final FileDeleteMarkerKey key) throws IOException { | ||
output.writeUTF(key.indexName); | ||
output.writeUTF(key.fileName); | ||
} | ||
|
||
@Override | ||
public FileDeleteMarkerKey readObject(final ObjectInput input) throws IOException { | ||
String indexName = input.readUTF(); | ||
String fileName = input.readUTF(); | ||
return new FileDeleteMarkerKey(indexName, fileName); | ||
} | ||
|
||
@Override | ||
public Integer getId() { | ||
return ExternalizerIds.FILE_DELETE_MARKER_KEY; | ||
} | ||
|
||
@Override | ||
public Set<Class<? extends FileDeleteMarkerKey>> getTypeClasses() { | ||
return Util.<Class<? extends FileDeleteMarkerKey>>asSet(FileDeleteMarkerKey.class); | ||
} | ||
|
||
} | ||
} |
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
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
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
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
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