forked from voldemort/voldemort
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a jna mlock to map and ping index files for RO stores in
memory
- Loading branch information
Showing
15 changed files
with
997 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package voldemort.store.readonly.io; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class BaseCloser<T> { | ||
|
||
protected List<T> delegates = new ArrayList(); | ||
|
||
private Throwable cause = null; | ||
|
||
private boolean executed = false; | ||
|
||
public BaseCloser() {} | ||
|
||
public BaseCloser(List<T> delegates) { | ||
this.delegates = delegates; | ||
} | ||
|
||
public BaseCloser(T... delegates) { | ||
add(delegates); | ||
} | ||
|
||
public void add(T delegate) { | ||
delegates.add(delegate); | ||
} | ||
|
||
public void add(T... delegates) { | ||
for(T current: delegates) { | ||
this.delegates.add(current); | ||
} | ||
} | ||
|
||
public void setCause(Throwable cause) { | ||
this.cause = cause; | ||
} | ||
|
||
protected boolean executed() { | ||
return executed; | ||
} | ||
|
||
protected void exec() throws GroupIOException { | ||
|
||
if(executed) | ||
return; | ||
|
||
GroupIOException exc = null; | ||
|
||
if(cause != null) | ||
exc = new GroupIOException(cause); | ||
|
||
for(T current: delegates) { | ||
|
||
if(current == null) | ||
continue; | ||
|
||
try { | ||
|
||
onDelegate(current); | ||
|
||
} catch(Throwable t) { | ||
|
||
if(exc == null) { | ||
exc = new GroupIOException(t); | ||
} else { | ||
exc.addSuppressed(t); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
executed = true; | ||
|
||
if(exc != null) | ||
throw exc; | ||
|
||
} | ||
|
||
protected abstract void onDelegate(T delegate) throws IOException; | ||
|
||
} |
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,42 @@ | ||
package voldemort.store.readonly.io; | ||
|
||
import java.io.File; | ||
import java.nio.channels.FileChannel; | ||
|
||
/** | ||
* | ||
*/ | ||
public class BaseMappedFile { | ||
|
||
protected FileChannel channel; | ||
|
||
protected long offset = 0; | ||
|
||
protected long length = 0; | ||
|
||
protected Closer closer = new Closer(); | ||
|
||
protected File file; | ||
|
||
protected int fd; | ||
|
||
protected boolean fadvise = true; | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
public int getFd() { | ||
return fd; | ||
} | ||
|
||
public boolean isClosed() { | ||
return closer.isClosed(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return file.toString(); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/java/voldemort/store/readonly/io/ByteBufferCloser.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,29 @@ | ||
package voldemort.store.readonly.io; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* A closeable which is smart enough to work on byte buffers. | ||
*/ | ||
public class ByteBufferCloser implements Closeable { | ||
|
||
private ByteBuffer buff; | ||
|
||
public ByteBufferCloser(ByteBuffer buff) { | ||
this.buff = buff; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
|
||
sun.misc.Cleaner cl = ((sun.nio.ch.DirectBuffer) buff).cleaner(); | ||
|
||
if(cl != null) { | ||
cl.clean(); | ||
} | ||
|
||
} | ||
|
||
} |
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,36 @@ | ||
package voldemort.store.readonly.io; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class Closer extends BaseCloser<Closeable> implements Closeable { | ||
|
||
public Closer() {} | ||
|
||
public Closer(List delegates) { | ||
this.delegates = (List<Closeable>) delegates; | ||
} | ||
|
||
public Closer(Closeable... delegates) { | ||
add(delegates); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
exec(); | ||
} | ||
|
||
public boolean closed() { | ||
return executed(); | ||
} | ||
|
||
public boolean isClosed() { | ||
return executed(); | ||
} | ||
|
||
protected void onDelegate(Closeable delegate) throws IOException { | ||
delegate.close(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/java/voldemort/store/readonly/io/GroupIOException.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,46 @@ | ||
package voldemort.store.readonly.io; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GroupIOException extends IOException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
List<Throwable> suppressed = new ArrayList<Throwable>(); | ||
|
||
public GroupIOException(Throwable cause) { | ||
suppressed.add(cause); | ||
} | ||
|
||
public void addSuppressed(Throwable t) { | ||
suppressed.add(t); | ||
} | ||
|
||
@Override | ||
public void printStackTrace(PrintStream out) { | ||
|
||
for(Throwable current: suppressed) { | ||
current.printStackTrace(out); | ||
} | ||
|
||
// this will print ourselves AND the cause... | ||
super.printStackTrace(out); | ||
|
||
} | ||
|
||
@Override | ||
public void printStackTrace(PrintWriter out) { | ||
|
||
for(Throwable current: suppressed) { | ||
current.printStackTrace(out); | ||
} | ||
|
||
// this will print ourselves AND the cause... | ||
super.printStackTrace(out); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.