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
}
}
}
}
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);
}
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();
}
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");
}
}
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();
}
Aggregations