use of com.orientechnologies.orient.core.storage.cache.OWriteCache in project orientdb by orientechnologies.
the class ClassTest method testRenameClusterAlreadyExists.
@Test
public void testRenameClusterAlreadyExists() {
OSchema schema = db.getMetadata().getSchema();
OClass classOne = schema.createClass("ClassOne");
OClass classTwo = schema.createClass("ClassTwo");
final int clusterId = db.addCluster("classthree");
classTwo.addClusterId(clusterId);
ODocument document = new ODocument("ClassTwo");
document.save("classthree");
document = new ODocument("ClassTwo");
document.save();
document = new ODocument("ClassOne");
document.save();
Assert.assertEquals(db.countClass("ClassTwo"), 2);
Assert.assertEquals(db.countClass("ClassOne"), 1);
classOne.setName("ClassThree");
final OStorage storage = db.getStorage();
final OAbstractPaginatedStorage paginatedStorage = (OAbstractPaginatedStorage) storage;
final OWriteCache writeCache = paginatedStorage.getWriteCache();
Assert.assertTrue(writeCache.exists("classone" + OPaginatedCluster.DEF_EXTENSION));
Assert.assertEquals(db.countClass("ClassTwo"), 2);
Assert.assertEquals(db.countClass("ClassThree"), 1);
classOne.setName("ClassOne");
Assert.assertTrue(writeCache.exists("classone" + OPaginatedCluster.DEF_EXTENSION));
Assert.assertEquals(db.countClass("ClassTwo"), 2);
Assert.assertEquals(db.countClass("ClassOne"), 1);
}
use of com.orientechnologies.orient.core.storage.cache.OWriteCache in project orientdb by orientechnologies.
the class OLocalHashTableWALTest method restoreDataFromWAL.
private void restoreDataFromWAL() throws IOException {
OWriteAheadLog log = ((OAbstractPaginatedStorage) databaseDocumentTx.getStorage()).getWALInstance();
OLogSequenceNumber lsn = log.begin();
List<OWALRecord> atomicUnit = new ArrayList<OWALRecord>();
List<OWALRecord> batch = new ArrayList<OWALRecord>();
boolean atomicChangeIsProcessed = false;
while (lsn != null) {
OWALRecord walRecord = log.read(lsn);
batch.add(walRecord);
if (batch.size() >= 1000) {
atomicChangeIsProcessed = restoreDataFromBatch(atomicChangeIsProcessed, atomicUnit, batch);
batch = new ArrayList<OWALRecord>();
}
lsn = log.next(lsn);
}
if (batch.size() > 0) {
restoreDataFromBatch(atomicChangeIsProcessed, atomicUnit, batch);
batch = null;
}
Assert.assertTrue(atomicUnit.isEmpty());
OWriteCache writeCache = ((OAbstractPaginatedStorage) expectedDatabaseDocumentTx.getStorage()).getWriteCache();
writeCache.flush();
}
use of com.orientechnologies.orient.core.storage.cache.OWriteCache in project orientdb by orientechnologies.
the class OLocalHashTableWALTest method restoreDataFromBatch.
private boolean restoreDataFromBatch(boolean atomicChangeIsProcessed, List<OWALRecord> atomicUnit, List<OWALRecord> records) throws IOException {
final OReadCache expectedReadCache = ((OAbstractPaginatedStorage) expectedDatabaseDocumentTx.getStorage()).getReadCache();
final OWriteCache expectedWriteCache = ((OAbstractPaginatedStorage) expectedDatabaseDocumentTx.getStorage()).getWriteCache();
for (OWALRecord walRecord : records) {
if (walRecord instanceof OOperationUnitBodyRecord)
atomicUnit.add(walRecord);
if (!atomicChangeIsProcessed && walRecord instanceof OAtomicUnitStartRecord) {
atomicChangeIsProcessed = true;
} else if (walRecord instanceof OAtomicUnitEndRecord) {
atomicChangeIsProcessed = false;
for (OWALRecord restoreRecord : atomicUnit) {
if (restoreRecord instanceof OAtomicUnitStartRecord || restoreRecord instanceof OAtomicUnitEndRecord || restoreRecord instanceof ONonTxOperationPerformedWALRecord || restoreRecord instanceof OFullCheckpointStartRecord || restoreRecord instanceof OCheckpointEndRecord)
continue;
if (restoreRecord instanceof OUpdatePageRecord) {
final OUpdatePageRecord updatePageRecord = (OUpdatePageRecord) restoreRecord;
final long fileId = updatePageRecord.getFileId();
final long pageIndex = updatePageRecord.getPageIndex();
OCacheEntry cacheEntry = expectedReadCache.load(fileId, pageIndex, true, expectedWriteCache, 1);
if (cacheEntry == null)
do {
cacheEntry = expectedReadCache.allocateNewPage(fileId, expectedWriteCache);
} while (cacheEntry.getPageIndex() != pageIndex);
cacheEntry.acquireExclusiveLock();
try {
ODurablePage durablePage = new ODurablePage(cacheEntry, null);
durablePage.restoreChanges(updatePageRecord.getChanges());
durablePage.setLsn(updatePageRecord.getLsn());
} finally {
cacheEntry.releaseExclusiveLock();
expectedReadCache.release(cacheEntry, expectedWriteCache);
}
} else if (restoreRecord instanceof OFileCreatedWALRecord) {
final OFileCreatedWALRecord fileCreatedCreatedRecord = (OFileCreatedWALRecord) restoreRecord;
String fileName = fileCreatedCreatedRecord.getFileName().replace("actualLocalHashTable", "expectedLocalHashTable");
if (!expectedWriteCache.exists(fileName))
expectedReadCache.addFile(fileName, fileCreatedCreatedRecord.getFileId(), expectedWriteCache);
}
}
atomicUnit.clear();
} else {
Assert.assertTrue(walRecord instanceof OUpdatePageRecord || walRecord instanceof OFileCreatedWALRecord || walRecord instanceof ONonTxOperationPerformedWALRecord || walRecord instanceof OFullCheckpointStartRecord || walRecord instanceof OCheckpointEndRecord || walRecord instanceof OFuzzyCheckpointStartRecord || walRecord instanceof OFuzzyCheckpointEndRecord);
}
}
return atomicChangeIsProcessed;
}
use of com.orientechnologies.orient.core.storage.cache.OWriteCache in project orientdb by orientechnologies.
the class IndexTest method testValuesContainerIsRemovedIfIndexIsRemoved.
public void testValuesContainerIsRemovedIfIndexIsRemoved() {
if (database.getURL().startsWith("remote:"))
return;
final OSchema schema = database.getMetadata().getSchema();
OClass clazz = schema.createClass("ValuesContainerIsRemovedIfIndexIsRemovedClass", 1, null);
clazz.createProperty("val", OType.STRING);
database.command(new OCommandSQL("create index ValuesContainerIsRemovedIfIndexIsRemovedIndex on ValuesContainerIsRemovedIfIndexIsRemovedClass (val) notunique")).execute();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 100; j++) {
ODocument document = new ODocument("ValuesContainerIsRemovedIfIndexIsRemovedClass");
document.field("val", "value" + i);
document.save();
}
}
final OAbstractPaginatedStorage storageLocalAbstract = (OAbstractPaginatedStorage) database.getStorage();
final OWriteCache writeCache = storageLocalAbstract.getWriteCache();
Assert.assertTrue(writeCache.exists("ValuesContainerIsRemovedIfIndexIsRemovedIndex.irs"));
database.command(new OCommandSQL("drop index ValuesContainerIsRemovedIfIndexIsRemovedIndex")).execute();
Assert.assertTrue(!writeCache.exists("ValuesContainerIsRemovedIfIndexIsRemovedIndex.irs"));
}
Aggregations