use of voldemort.store.readonly.chunk.ChunkedFileSet in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleGetROStorageFileList.
public VAdminProto.GetROStorageFileListResponse handleGetROStorageFileList(VAdminProto.GetROStorageFileListRequest request) {
String storeName = request.getStoreName();
VAdminProto.GetROStorageFileListResponse.Builder response = VAdminProto.GetROStorageFileListResponse.newBuilder();
try {
ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
ChunkedFileSet chunkedFileSet = store.getChunkedFileSet();
response.addAllFileName(chunkedFileSet.getFileNames());
response.addAllIndexFileSize(chunkedFileSet.getIndexFileSizes());
response.addAllDataFileSize(chunkedFileSet.getDataFileSizes());
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleGetROStorageFileList failed for request(" + request.toString() + ")", e);
}
return response.build();
}
use of voldemort.store.readonly.chunk.ChunkedFileSet in project voldemort by voldemort.
the class ReadOnlyStorageEngine method open.
/**
* Open the store with the version directory specified. If null is specified
* we open the directory with the maximum version
*
* @param versionDir Version Directory to open. If null, we open the max
* versioned / latest directory
*/
public void open(File versionDir) {
/* acquire modification lock */
fileModificationLock.writeLock().lock();
try {
/* check that the store is currently closed */
if (isOpen)
throw new IllegalStateException("Attempt to open already open store.");
// Find version directory from symbolic link or max version id
if (versionDir == null) {
versionDir = ReadOnlyUtils.getCurrentVersion(storeDir);
if (versionDir == null)
versionDir = new File(storeDir, "version-0");
}
// Set the max version id
long versionId = ReadOnlyUtils.getVersionId(versionDir);
if (versionId == -1) {
throw new VoldemortException("Unable to parse id from version directory " + versionDir.getAbsolutePath());
}
Utils.mkdirs(versionDir);
// Validate symbolic link, and create it if it doesn't already exist
Utils.symlink(versionDir.getAbsolutePath(), storeDir.getAbsolutePath() + File.separator + "latest");
this.fileSet = new ChunkedFileSet(versionDir, routingStrategy, nodeId, maxValueBufferAllocationSize);
storeVersionManager.syncInternalStateFromFileSystem(false);
this.lastSwapped = System.currentTimeMillis();
this.isOpen = true;
} catch (IOException e) {
logger.error("Error in opening store", e);
} finally {
fileModificationLock.writeLock().unlock();
}
}
use of voldemort.store.readonly.chunk.ChunkedFileSet in project voldemort by voldemort.
the class ChunkedFileSetTest method testCollision.
@Test
public void testCollision() throws Exception {
File fileDir = TestUtils.createTempDir();
File dataFile = new File(fileDir + File.separator + "0_0_0.data");
dataFile.deleteOnExit();
FileOutputStream fw = new FileOutputStream(dataFile.getAbsoluteFile());
DataOutputStream outputStream = new DataOutputStream(fw);
/*
* 4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa200a8284bf36e8e4b55b35f427593d849676da0d1555d8360fb5f07fea2
* and the (different by two bits)
* 4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa202a8284bf36e8e4b55b35f427593d849676da0d1d55d8360fb5f07fea2
* both have MD5 hash 008ee33a9d58b51cfeb425b0959121c9
*/
String[] md5collision = { "4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa200a8284bf36e8e4b55b35f427593d849676da0d1555d8360fb5f07fea2", "4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa202a8284bf36e8e4b55b35f427593d849676da0d1d55d8360fb5f07fea2" };
outputStream.writeShort(2);
for (int i = 0; i < 2; i++) {
String input = md5collision[i];
byte[] hexInput = ByteUtils.fromHexString(input);
outputStream.writeInt(hexInput.length);
outputStream.writeInt(hexInput.length);
outputStream.write(hexInput);
outputStream.write(hexInput);
}
outputStream.close();
fw.close();
File indexFile = new File(fileDir + File.separator + "0_0_0.index");
indexFile.createNewFile();
indexFile.deleteOnExit();
ChunkedFileSet fileSet = new ChunkedFileSet(fileDir, getTempStrategy(), NODE_ID, VoldemortConfig.DEFAULT_RO_MAX_VALUE_BUFFER_ALLOCATION_SIZE);
for (int i = 0; i < 2; i++) {
String input = md5collision[i];
byte[] hexInput = ByteUtils.fromHexString(input);
byte[] hexValue = fileSet.readValue(hexInput, 0, 0);
Assert.assertArrayEquals(hexInput, hexValue);
}
}
Aggregations