Search in sources :

Example 31 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage 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 32 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage 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 33 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocalTest method beforeClass.

@BeforeClass
public void beforeClass() {
    String buildDirectory = System.getProperty("buildDirectory");
    if (buildDirectory == null)
        buildDirectory = "./target";
    databaseDocumentTx = new ODatabaseDocumentTx("plocal:" + buildDirectory + "/localSBTreeBonsaiTest");
    if (databaseDocumentTx.exists()) {
        databaseDocumentTx.open("admin", "admin");
        databaseDocumentTx.drop();
    }
    databaseDocumentTx.create();
    sbTree = new OSBTreeBonsaiLocal<Integer, OIdentifiable>("actualSBTreeBonsaiLocalTest", ".irs", (OAbstractPaginatedStorage) databaseDocumentTx.getStorage());
    sbTree.create(OIntegerSerializer.INSTANCE, OLinkSerializer.INSTANCE);
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) BeforeClass(org.testng.annotations.BeforeClass)

Example 34 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class LocalPaginatedClusterTest method beforeClass.

@BeforeClass
public void beforeClass() throws IOException {
    System.out.println("Start LocalPaginatedClusterTest");
    buildDirectory = System.getProperty("buildDirectory");
    if (buildDirectory == null || buildDirectory.isEmpty())
        buildDirectory = ".";
    buildDirectory += "/localPaginatedClusterTest";
    databaseDocumentTx = new ODatabaseDocumentTx("plocal:" + buildDirectory + File.separator + LocalPaginatedClusterTest.class.getSimpleName());
    if (databaseDocumentTx.exists()) {
        databaseDocumentTx.open("admin", "admin");
        databaseDocumentTx.drop();
    }
    databaseDocumentTx.create();
    OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) databaseDocumentTx.getStorage();
    paginatedCluster = new OPaginatedCluster("paginatedClusterTest", storage);
    paginatedCluster.configure(storage, 5, "paginatedClusterTest", buildDirectory, -1);
    paginatedCluster.create(-1);
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) BeforeClass(org.testng.annotations.BeforeClass)

Example 35 with OAbstractPaginatedStorage

use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.

the class NonDurableTxTest method before.

@Before
public void before() {
    String buildDirectory = System.getProperty("buildDirectory");
    if (buildDirectory == null)
        buildDirectory = ".";
    db = new ODatabaseDocumentTx("plocal:" + buildDirectory + File.separator + NonDurableTxTest.class.getSimpleName());
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) db.getStorage();
    atomicOperationsManager = storage.getAtomicOperationsManager();
    wal = storage.getWALInstance();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) Before(org.junit.Before)

Aggregations

OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)38 OStorage (com.orientechnologies.orient.core.storage.OStorage)12 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)9 OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)7 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)5 Test (org.testng.annotations.Test)5 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 OLocalPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage)4 File (java.io.File)4 BeforeClass (org.testng.annotations.BeforeClass)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 IOException (java.io.IOException)3 OLockException (com.orientechnologies.common.concur.lock.OLockException)2 OException (com.orientechnologies.common.exception.OException)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 ORID (com.orientechnologies.orient.core.id.ORID)2 ORemoteIndexEngine (com.orientechnologies.orient.core.index.engine.ORemoteIndexEngine)2