Search in sources :

Example 6 with OWriteCache

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);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 7 with OWriteCache

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();
}
Also used : OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) ArrayList(java.util.ArrayList) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)

Example 8 with OWriteCache

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;
}
Also used : ODurablePage(com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OReadCache(com.orientechnologies.orient.core.storage.cache.OReadCache) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)

Example 9 with OWriteCache

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"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)9 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)7 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OReadCache (com.orientechnologies.orient.core.storage.cache.OReadCache)3 Test (org.testng.annotations.Test)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)2 IOException (java.io.IOException)2 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)1 OWOWCache (com.orientechnologies.orient.core.storage.cache.local.OWOWCache)1 ODurablePage (com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage)1 ArrayList (java.util.ArrayList)1