Search in sources :

Example 46 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class ServerRun method closeStorages.

public void closeStorages() {
    for (OStorage s : Orient.instance().getStorages()) {
        if (s instanceof OLocalPaginatedStorage && new File(((OLocalPaginatedStorage) s).getStoragePath()).getAbsolutePath().startsWith(getDatabasePath(""))) {
            try {
                s.close(true, false);
                Orient.instance().unregisterStorage(s);
            } catch (Exception e) {
            // IGNORE IT
            }
        }
    }
}
Also used : OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) OStorage(com.orientechnologies.orient.core.storage.OStorage) File(java.io.File) IOException(java.io.IOException)

Example 47 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class LocalPaginatedStorageUpdateCrashRestoreIT method compareDocuments.

private void compareDocuments(long lastTs) {
    long minTs = Long.MAX_VALUE;
    baseDocumentTx.activateOnCurrentThread();
    int clusterId = baseDocumentTx.getClusterIdByName("TestClass");
    OStorage baseStorage = baseDocumentTx.getStorage();
    OPhysicalPosition[] physicalPositions = baseStorage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(0));
    int recordsRestored = 0;
    int recordsTested = 0;
    while (physicalPositions.length > 0) {
        final ORecordId rid = new ORecordId(clusterId);
        for (OPhysicalPosition physicalPosition : physicalPositions) {
            rid.setClusterPosition(physicalPosition.clusterPosition);
            baseDocumentTx.activateOnCurrentThread();
            ODocument baseDocument = baseDocumentTx.load(rid);
            testDocumentTx.activateOnCurrentThread();
            List<ODocument> testDocuments = testDocumentTx.query(new OSQLSynchQuery<ODocument>("select from TestClass where id  = " + baseDocument.field("id")));
            Assert.assertTrue(!testDocuments.isEmpty());
            ODocument testDocument = testDocuments.get(0);
            if (testDocument.field("timestamp").equals(baseDocument.field("timestamp")) && testDocument.field("stringValue").equals(baseDocument.field("stringValue"))) {
                recordsRestored++;
            } else {
                if (((Long) baseDocument.field("timestamp")) < minTs)
                    minTs = baseDocument.field("timestamp");
            }
            recordsTested++;
            if (recordsTested % 10000 == 0)
                System.out.println(recordsTested + " were tested, " + recordsRestored + " were restored ...");
        }
        physicalPositions = baseStorage.higherPhysicalPositions(clusterId, physicalPositions[physicalPositions.length - 1]);
    }
    System.out.println(recordsRestored + " records were restored. Total records " + recordsTested + ". lost records " + (recordsTested - recordsRestored));
    long maxInterval = minTs == Long.MAX_VALUE ? 0 : lastTs - minTs;
    System.out.println("Lost records max interval (ms) : " + maxInterval);
    assertThat(recordsTested - recordsRestored).isLessThan(120);
    assertThat(maxInterval).isLessThan(2000);
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 48 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class LocalPaginatedStorageLinkBagCrashRestoreIT method compareDocuments.

private void compareDocuments(long lastTs) {
    ODatabaseDocumentTx base_db = new ODatabaseDocumentTx("plocal:" + buildDir + "/baseLocalPaginatedStorageLinkBagCrashRestore");
    base_db.open("admin", "admin");
    ODatabaseDocumentTx test_db = new ODatabaseDocumentTx("plocal:" + buildDir + "/testLocalPaginatedStorageLinkBagCrashRestore");
    test_db.open("admin", "admin");
    long minTs = Long.MAX_VALUE;
    OStorage baseStorage = base_db.getStorage();
    OPhysicalPosition[] physicalPositions = baseStorage.ceilingPhysicalPositions(defaultClusterId, new OPhysicalPosition(0));
    int recordsRestored = 0;
    int recordsTested = 0;
    while (physicalPositions.length > 0) {
        final ORecordId rid = new ORecordId(defaultClusterId);
        for (OPhysicalPosition physicalPosition : physicalPositions) {
            rid.setClusterPosition(physicalPosition.clusterPosition);
            ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
            ODocument baseDocument = base_db.load(rid);
            baseDocument.setLazyLoad(false);
            ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
            ODocument testDocument = test_db.load(rid);
            if (testDocument == null) {
                ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
                if (((Long) baseDocument.field("ts")) < minTs)
                    minTs = baseDocument.field("ts");
            } else {
                testDocument.setLazyLoad(false);
                long baseTs;
                long testTs;
                ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
                baseTs = baseDocument.field("ts");
                ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
                testTs = testDocument.field("ts");
                boolean equals = baseTs == testTs;
                if (equals) {
                    Set<ORID> baseRids = new HashSet<ORID>();
                    ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
                    ORidBag baseRidBag = baseDocument.field("ridBag");
                    for (OIdentifiable baseIdentifiable : baseRidBag) baseRids.add(baseIdentifiable.getIdentity());
                    Set<ORID> testRids = new HashSet<ORID>();
                    ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
                    ORidBag testRidBag = testDocument.field("ridBag");
                    for (OIdentifiable testIdentifiable : testRidBag) testRids.add(testIdentifiable.getIdentity());
                    equals = baseRids.equals(testRids);
                }
                if (!equals) {
                    if (((Long) baseDocument.field("ts")) < minTs)
                        minTs = baseDocument.field("ts");
                } else
                    recordsRestored++;
            }
            recordsTested++;
            if (recordsTested % 10000 == 0)
                System.out.println(recordsTested + " were tested, " + recordsRestored + " were restored ...");
        }
        physicalPositions = baseStorage.higherPhysicalPositions(defaultClusterId, physicalPositions[physicalPositions.length - 1]);
    }
    System.out.println(recordsRestored + " records were restored. Total records " + recordsTested + ". lost records " + (recordsTested - recordsRestored));
    long maxInterval = minTs == Long.MAX_VALUE ? 0 : lastTs - minTs;
    System.out.println("Lost records max interval (ms) : " + maxInterval);
    assertThat(maxInterval).isLessThan(2000);
    base_db.activateOnCurrentThread();
    base_db.close();
    test_db.activateOnCurrentThread();
    test_db.close();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 49 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method disconnect.

@ConsoleCommand(aliases = { "close database" }, description = "Disconnect from the current database", onlineHelp = "Console-Command-Disconnect")
public void disconnect() {
    if (serverAdmin != null) {
        message("\nDisconnecting from remote server [" + serverAdmin.getURL() + "]...");
        serverAdmin.close(true);
        serverAdmin = null;
        message("\nOK");
    }
    if (currentDatabase != null) {
        message("\nDisconnecting from the database [" + currentDatabaseName + "]...");
        final OStorage stg = Orient.instance().getStorage(currentDatabase.getURL());
        currentDatabase.activateOnCurrentThread();
        if (!currentDatabase.isClosed())
            currentDatabase.close();
        // FORCE CLOSING OF STORAGE: THIS CLEAN UP REMOTE CONNECTIONS
        if (stg != null)
            stg.close(true, false);
        currentDatabase = null;
        currentDatabaseName = null;
        currentRecord = null;
        message("OK");
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 50 with OStorage

use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.

the class OIndexManagerAbstract method getServerLocale.

protected Locale getServerLocale() {
    ODatabaseDocumentInternal db = getDatabase();
    OStorage storage = db.getStorage();
    OStorageConfiguration configuration = storage.getConfiguration();
    return configuration.getLocaleInstance();
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

OStorage (com.orientechnologies.orient.core.storage.OStorage)90 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)31 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)22 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)21 ORecordId (com.orientechnologies.orient.core.id.ORecordId)20 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)18 OPhysicalPosition (com.orientechnologies.orient.core.storage.OPhysicalPosition)12 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)11 File (java.io.File)11 ORID (com.orientechnologies.orient.core.id.ORID)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)7 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)7 Test (org.testng.annotations.Test)7 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)6 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)5 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5