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
4801bdf
commit 1cac13d
Showing
8 changed files
with
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
## master | ||
|
||
* Update to bouncy-castle 1.68 | ||
* Added database type "atomic_file" for use with MrPlow | ||
|
||
## 1.8.0 | ||
|
||
|
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,41 @@ | ||
package snowblossom.lib.db.atomicfile; | ||
|
||
import duckutil.Config; | ||
import java.io.File; | ||
import java.util.logging.Logger; | ||
import snowblossom.lib.db.DBMap; | ||
import snowblossom.lib.db.DBMapMutationSet; | ||
import snowblossom.lib.db.DBProvider; | ||
|
||
public class AtomicFileDB extends DBProvider | ||
{ | ||
private final File base; | ||
|
||
public AtomicFileDB(Config config) | ||
throws Exception | ||
{ | ||
super(config); | ||
config.require("db_path"); | ||
|
||
String path = config.get("db_path"); | ||
|
||
base = new File(path); | ||
base.mkdirs(); | ||
|
||
logger.info(String.format("Loading AtomicFileDB with path %s", path)); | ||
|
||
} | ||
|
||
@Override | ||
public DBMapMutationSet openMutationMapSet(String name) throws Exception | ||
{ | ||
throw new Exception("NOT IMPLEMENTED"); | ||
} | ||
|
||
@Override | ||
public DBMap openMap(String name) throws Exception | ||
{ | ||
return new AtomicFileMap(new File(base, name)); | ||
} | ||
|
||
} |
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,82 @@ | ||
package snowblossom.lib.db.atomicfile; | ||
|
||
import com.google.protobuf.ByteString; | ||
import duckutil.AtomicFileOutputStream; | ||
import java.io.DataInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import snowblossom.lib.HexUtil; | ||
import snowblossom.lib.db.DBMap; | ||
|
||
public class AtomicFileMap extends DBMap | ||
{ | ||
private final File base; | ||
|
||
public AtomicFileMap(File base) | ||
{ | ||
this.base = base; | ||
} | ||
|
||
@Override | ||
public void put(ByteString key, ByteString value) | ||
{ | ||
base.mkdirs(); | ||
|
||
File f = getFileForKey(key); | ||
|
||
try | ||
{ | ||
AtomicFileOutputStream a_out = new AtomicFileOutputStream(f); | ||
a_out.write(value.toByteArray()); | ||
a_out.flush(); | ||
a_out.close(); | ||
} | ||
catch(java.io.IOException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
@Override | ||
public ByteString get(ByteString key) | ||
{ | ||
File f = getFileForKey(key); | ||
if (!f.exists()) | ||
{ | ||
return null; | ||
} | ||
|
||
if (f.length() > 1e9) | ||
{ | ||
throw new RuntimeException("File too long to read: " + f); | ||
} | ||
int sz = (int)f.length(); | ||
byte[] buff = new byte[sz]; | ||
try | ||
{ | ||
DataInputStream din=new DataInputStream(new FileInputStream(f)); | ||
din.readFully(buff); | ||
din.close(); | ||
|
||
return ByteString.copyFrom(buff); | ||
} | ||
catch(java.io.IOException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
|
||
public File getFileForKey(ByteString key) | ||
{ | ||
String name = HexUtil.getHexString(key); | ||
|
||
return new File(base, name); | ||
|
||
} | ||
|
||
} |
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