use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class LocalPaginatedStorageIncrementalSync method incrementalSyncIteration.
private void incrementalSyncIteration(String buildDirectory) throws Exception {
OLogSequenceNumber startLSN = ((OAbstractPaginatedStorage) originalDB.getStorage()).getWALInstance().end();
final Random rnd = new Random();
int created = 0;
int updated = 0;
int deleted = 0;
while (created + updated + deleted < 10000) {
final int operation = rnd.nextInt(3);
switch(operation) {
case 0:
createRecord(rnd);
created++;
break;
case 1:
if (updateRecord(rnd))
updated++;
break;
case 2:
if (deleteRecord(rnd))
deleted++;
break;
}
}
System.out.println("Created " + created);
System.out.println("Updated " + updated);
System.out.println("Deleted " + deleted);
final File changesFile = new File(buildDirectory, LocalPaginatedStorageIncrementalSync.class.getSimpleName() + ".dt");
if (changesFile.exists()) {
Assert.assertTrue(changesFile.delete());
}
RandomAccessFile dataFile = new RandomAccessFile(changesFile, "rw");
try {
FileChannel channel = dataFile.getChannel();
final OutputStream outputStream = Channels.newOutputStream(channel);
final OutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
((OAbstractPaginatedStorage) originalDB.getStorage()).recordsChangedAfterLSN(startLSN, bufferedOutputStream, new HashSet<String>(), null);
bufferedOutputStream.close();
dataFile.close();
dataFile = new RandomAccessFile(changesFile, "rw");
channel = dataFile.getChannel();
final InputStream inputStream = Channels.newInputStream(channel);
final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
replicateDelta(syncDB, bufferedInputStream);
} finally {
dataFile.close();
}
assertDatabasesAreInSynch();
Assert.assertTrue(changesFile.delete());
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method executeReadRecords.
/**
* This method is internal, it can be subject to signature change or be removed, do not use.
*
* @Internal
*/
public Set<ORecord> executeReadRecords(final Set<ORecordId> iRids, final boolean ignoreCache) {
checkOpeness();
checkIfActive();
getMetadata().makeThreadLocalSchemaSnapshot();
ORecordSerializationContext.pushContext();
try {
final Set<ORecord> records = new HashSet<ORecord>(iRids.size() > 0 ? iRids.size() : 1);
if (iRids.isEmpty())
return records;
final Collection<ORecordId> rids = new ArrayList<ORecordId>(iRids);
for (Iterator<ORecordId> it = rids.iterator(); it.hasNext(); ) {
final ORecordId rid = it.next();
// SEARCH IN LOCAL TX
ORecord record = getTransaction().getRecord(rid);
if (record == OTransactionRealAbstract.DELETED_RECORD) {
// DELETED IN TX
it.remove();
continue;
}
if (record == null && !ignoreCache)
// SEARCH INTO THE CACHE
record = getLocalCache().findRecord(rid);
if (record != null) {
// FOUND FROM CACHE
records.add(record);
it.remove();
}
}
final Collection<OPair<ORecordId, ORawBuffer>> rawRecords = ((OAbstractPaginatedStorage) storage.getUnderlying()).readRecords(rids);
for (OPair<ORecordId, ORawBuffer> entry : rawRecords) {
// NO SAME RECORD TYPE: CAN'T REUSE OLD ONE BUT CREATE A NEW ONE FOR IT
final ORecord record = Orient.instance().getRecordFactoryManager().newInstance(entry.value.recordType);
ORecordInternal.fill(record, entry.key, entry.value.version, entry.value.buffer, false);
records.add(record);
}
return records;
} finally {
ORecordSerializationContext.pullContext();
getMetadata().clearThreadLocalSchemaSnapshot();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class ODefaultIndexFactory method createIndexEngine.
@Override
public OIndexEngine createIndexEngine(String algorithm, String name, Boolean durableInNonTxMode, OStorage storage, int version, Map<String, String> engineProperties) {
final OIndexEngine indexEngine;
final String storageType = storage.getType();
if (storageType.equals("memory") || storageType.equals("plocal"))
indexEngine = new OSBTreeIndexEngine(name, durableInNonTxMode, (OAbstractPaginatedStorage) storage, version);
else if (storageType.equals("distributed"))
// DISTRIBUTED CASE: HANDLE IT AS FOR LOCAL
indexEngine = new OSBTreeIndexEngine(name, durableInNonTxMode, (OAbstractPaginatedStorage) storage.getUnderlying(), version);
else if (storageType.equals("remote"))
indexEngine = new ORemoteIndexEngine(name);
else
throw new OIndexException("Unsupported storage type: " + storageType);
return indexEngine;
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class OSchemaShared method fromStream.
/**
* Binds ODocument to POJO.
*/
@Override
public void fromStream() {
rwSpinLock.acquireWriteLock();
modificationCounter.get().increment();
try {
// READ CURRENT SCHEMA VERSION
final Integer schemaVersion = (Integer) document.field("schemaVersion");
if (schemaVersion == null) {
OLogManager.instance().error(this, "Database's schema is empty! Recreating the system classes and allow the opening of the database but double check the integrity of the database");
return;
} else if (schemaVersion != CURRENT_VERSION_NUMBER && VERSION_NUMBER_V5 != schemaVersion) {
// HANDLE SCHEMA UPGRADE
throw new OConfigurationException("Database schema is different. Please export your old database with the previous version of OrientDB and reimport it using the current one.");
}
properties.clear();
propertiesByNameType.clear();
List<ODocument> globalProperties = document.field("globalProperties");
boolean hasGlobalProperties = false;
if (globalProperties != null) {
hasGlobalProperties = true;
for (ODocument oDocument : globalProperties) {
OGlobalPropertyImpl prop = new OGlobalPropertyImpl();
prop.fromDocument(oDocument);
ensurePropertiesSize(prop.getId());
properties.set(prop.getId(), prop);
propertiesByNameType.put(prop.getName() + "|" + prop.getType().name(), prop);
}
}
// REGISTER ALL THE CLASSES
clustersToClasses.clear();
final Map<String, OClass> newClasses = new HashMap<String, OClass>();
OClassImpl cls;
Collection<ODocument> storedClasses = document.field("classes");
for (ODocument c : storedClasses) {
cls = new OClassImpl(this, c, (String) c.field("name"));
cls.fromStream();
if (classes.containsKey(cls.getName().toLowerCase())) {
cls = (OClassImpl) classes.get(cls.getName().toLowerCase());
cls.fromStream(c);
}
newClasses.put(cls.getName().toLowerCase(), cls);
if (cls.getShortName() != null)
newClasses.put(cls.getShortName().toLowerCase(), cls);
addClusterClassMap(cls);
}
classes.clear();
classes.putAll(newClasses);
// REBUILD THE INHERITANCE TREE
Collection<String> superClassNames;
String legacySuperClassName;
List<OClass> superClasses;
OClass superClass;
for (ODocument c : storedClasses) {
superClassNames = c.field("superClasses");
legacySuperClassName = c.field("superClass");
if (superClassNames == null)
superClassNames = new ArrayList<String>();
else
superClassNames = new HashSet<String>(superClassNames);
if (legacySuperClassName != null && !superClassNames.contains(legacySuperClassName))
superClassNames.add(legacySuperClassName);
if (!superClassNames.isEmpty()) {
// HAS A SUPER CLASS or CLASSES
cls = (OClassImpl) classes.get(((String) c.field("name")).toLowerCase());
superClasses = new ArrayList<OClass>(superClassNames.size());
for (String superClassName : superClassNames) {
superClass = classes.get(superClassName.toLowerCase());
if (superClass == null)
throw new OConfigurationException("Super class '" + superClassName + "' was declared in class '" + cls.getName() + "' but was not found in schema. Remove the dependency or create the class to continue.");
superClasses.add(superClass);
}
cls.setSuperClassesInternal(superClasses);
}
}
if (document.containsField("blobClusters"))
blobClusters = document.field("blobClusters");
if (!hasGlobalProperties) {
if (getDatabase().getStorage().getUnderlying() instanceof OAbstractPaginatedStorage)
saveInternal();
}
} finally {
version++;
modificationCounter.get().decrement();
rwSpinLock.releaseWriteLock();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage in project orientdb by orientechnologies.
the class LocalHashTableIterationTest method beforeClass.
@BeforeClass
public void beforeClass() {
String buildDirectory = System.getProperty("buildDirectory");
if (buildDirectory == null)
buildDirectory = ".";
databaseDocumentTx = new ODatabaseDocumentTx("plocal:" + buildDirectory + "/localHashTableIterationTest");
if (databaseDocumentTx.exists()) {
databaseDocumentTx.open("admin", "admin");
databaseDocumentTx.drop();
}
databaseDocumentTx.create();
OHashFunction<Integer> hashFunction = new OHashFunction<Integer>() {
@Override
public long hashCode(Integer value) {
return Long.MAX_VALUE / 2 + value;
}
};
localHashTable = new OLocalHashTable<Integer, String>("localHashTableIterationTest", ".imc", ".tsc", ".obf", ".nbh", hashFunction, false, (OAbstractPaginatedStorage) databaseDocumentTx.getStorage());
localHashTable.create(OIntegerSerializer.INSTANCE, OBinarySerializerFactory.getInstance().<String>getObjectSerializer(OType.STRING), null, true);
}
Aggregations