Further tweaks to storage
This commit is contained in:
parent
c2cb5d5725
commit
e2cfd990bb
@ -59,9 +59,7 @@ public class Storage {
|
|||||||
storage.increaseReference();
|
storage.increaseReference();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
StorageBase storageBase = new StorageBase(file);
|
storage = new Storage(file);
|
||||||
|
|
||||||
storage = new Storage(storageBase);
|
|
||||||
storages.put(file, storage);
|
storages.put(file, storage);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Unable to open storage", e);
|
logger.error("Unable to open storage", e);
|
||||||
@ -270,8 +268,8 @@ public class Storage {
|
|||||||
/**
|
/**
|
||||||
* Creates or opens a new database file.
|
* Creates or opens a new database file.
|
||||||
*/
|
*/
|
||||||
private Storage(StorageBase _storage) {
|
private Storage(File storageFile) throws IOException {
|
||||||
this.storage = _storage;
|
this.storage = new StorageBase(storageFile);
|
||||||
this.defaultKey = wrap("");
|
this.defaultKey = wrap("");
|
||||||
|
|
||||||
this.timer = new DelayTimer("Storage Writer", false, new DelayTimer.Callback() {
|
this.timer = new DelayTimer("Storage Writer", false, new DelayTimer.Callback() {
|
||||||
|
@ -93,6 +93,8 @@ public class StorageBase {
|
|||||||
* Creates or opens a new database file.
|
* Creates or opens a new database file.
|
||||||
*/
|
*/
|
||||||
StorageBase(File filePath) throws IOException {
|
StorageBase(File filePath) throws IOException {
|
||||||
|
this.logger.info("Opening storage file: '{}'", filePath.getAbsolutePath());
|
||||||
|
|
||||||
this.baseFile = filePath;
|
this.baseFile = filePath;
|
||||||
|
|
||||||
File parentFile = this.baseFile.getParentFile();
|
File parentFile = this.baseFile.getParentFile();
|
||||||
@ -119,6 +121,14 @@ public class StorageBase {
|
|||||||
this.file.setLength(indexPointer);
|
this.file.setLength(indexPointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.file.length() < this.dataPosition) {
|
||||||
|
this.logger.error("Corrupted storage file!");
|
||||||
|
throw new IllegalArgumentException("Unable to parse header information from storage. Maybe it's corrupted?");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.info("Storage version: {}", this.databaseVersion);
|
||||||
|
|
||||||
|
|
||||||
this.kryo = new Kryo();
|
this.kryo = new Kryo();
|
||||||
this.kryo.setRegistrationRequired(false);
|
this.kryo.setRegistrationRequired(false);
|
||||||
|
|
||||||
|
@ -10,14 +10,13 @@ import java.util.Arrays;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
import dorkbox.util.storage.Storage;
|
import dorkbox.util.storage.Storage;
|
||||||
|
|
||||||
/**
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
* Simple test class for the RecordsFile example. To run the test, set you CLASSPATH and then type
|
|
||||||
* "java hamner.dbtest.TestRecords"
|
|
||||||
*/
|
|
||||||
public class StorageTest {
|
public class StorageTest {
|
||||||
|
|
||||||
private static final String TEST_DB = "sampleFile.records";
|
private static final String TEST_DB = "sampleFile.records";
|
||||||
|
Loading…
Reference in New Issue
Block a user