Java源码示例:com.orientechnologies.orient.core.storage.OStorage
示例1
protected void replaceStorage(final OPartitionedDatabasePool pool, final OStorage storage) {
if (partitionsField != null) {
ODatabaseDocumentInternal originalDb = ODatabaseRecordThreadLocal.instance().getIfDefined();
try {
// use reflection as workaround until public API is available
for (Object partition : (Object[]) partitionsField.get(pool)) {
for (ODatabaseDocumentTx db : (Iterable<ODatabaseDocumentTx>) partitionQueueField.get(partition)) {
replaceStorage(db, storage);
}
}
}
catch (Exception | LinkageError e) {
log.warn("Problem replacing storage for {}", storage.getName(), e);
}
finally {
ODatabaseRecordThreadLocal.instance().set(originalDb);
}
}
}
示例2
private void replaceStorage(ODatabaseDocumentTx db, final OStorage storage) {
db.replaceStorage(storage);
if (!db.isClosed()) {
try {
// reload metadata for active connections if old schema is gone
if (db.getMetadata().getSchema().countClasses() == 0) {
log.debug("Reloading metadata for {} as storage has changed", db.getName());
db.activateOnCurrentThread();
db.getMetadata().reload();
}
}
catch (Exception e) {
log.warn("Problem reloading metadata for {}", db.getName(), e);
}
}
}
示例3
/**
* Returns an optional {@link EntityAdapter} that 'owns' the clusterId and is interested in resolving its conflicts.
*/
private Optional<EntityAdapter<?>> findResolvingAdapter(final OStorage storage, final int clusterId) {
if (!enabled) {
return empty();
}
String clusterKey = storage.getName() + '#' + clusterId; // clusterIds are not unique across DBs
String typeName = typeNamesByClusterKey.computeIfAbsent(clusterKey,
k -> findTypeName(storage.getPhysicalClusterNameById(clusterId)));
return ofNullable(typeName).map(resolvingAdapters::get);
}
示例4
@Override
public void replaceStorage(final OStorage storage) {
DatabasePoolSupport pool;
synchronized (pools) {
pool = pools.get(storage.getName());
}
if (pool != null) {
pool.replaceStorage(storage);
}
}
示例5
@Override
public void replaceStorage(final OStorage storage) {
try {
replaceStorage(delegate, storage);
}
finally {
replaceStorage(overflow, storage);
}
}
示例6
/**
* Attempts to resolve the potential conflict by delegating to the resolving entity adapter.
*/
@Override
@Nullable
public byte[] onUpdate(final OStorage storage,
final byte recordType,
final ORecordId rid,
final int recordVersion,
final byte[] changeContent,
final AtomicInteger dbVersion)
{
// most records won't have an entity adapter interested in resolving their conflicts
Optional<EntityAdapter<?>> adapter = findResolvingAdapter(storage, rid.getClusterId());
if (adapter.isPresent()) {
// attempt to load the current stored record content
byte[] storedContent = storage.readRecord(rid, null, false, false, null).getResult().getBuffer();
ConflictState state;
ODocument changeRecord = null;
if (recordType == RECORD_TYPE) {
// turn the stored content into a proper record
ODocument storedRecord = new ODocument(rid).fromStream(storedContent);
// retrieve the change we originally wanted to save
changeRecord = getChangeRecord(rid, changeContent);
// delegate conflict resolution to owning entity adapter
state = adapter.get().resolve(storedRecord, changeRecord);
log.trace("{} update of {} with {}", state, storedRecord, changeRecord);
}
else {
// binary content - no merging, we can only do a simple comparison
state = Arrays.equals(storedContent, changeContent) ? IGNORE : DENY;
log.trace("{} binary update of {}", state, rid);
}
switch (state) {
case IGNORE:
// for now treat "no-op" changes like ALLOW, but without any version bump
return null;
case ALLOW:
// go ahead with original change, but bump version if record was behind DB
dbVersion.set(max(dbVersion.get() + 1, recordVersion));
return null;
case MERGE:
// return merged content and bump version whether record was behind or not
dbVersion.set(max(dbVersion.get(), recordVersion) + 1);
return ofNullable(changeRecord).map(ODocument::toStream).orElse(null);
default:
break;
}
}
throw new OConcurrentModificationException(rid, dbVersion.get(), recordVersion, UPDATED);
}
示例7
@Override
public void replaceStorage(final OStorage storage) {
replaceStorage(delegate, storage);
}
示例8
private OStorage getStorage() {
return ODatabaseRecordThreadLocal.instance().get().getDatabaseOwner().getStorage();
}
示例9
private OStorage getStorage() {
return ODatabaseRecordThreadLocal.instance().get().getDatabaseOwner().getStorage();
}
示例10
/**
* Updates local pooled connections to use the given storage.
*
* @since 3.8
*
* @deprecated temporary workaround for https://www.prjhub.com/#/issues/9594
*/
@Deprecated
void replaceStorage(OStorage storage);
示例11
/**
* Updates local pooled connections to use the given storage.
*
* @since 3.8
*
* @deprecated temporary workaround for https://www.prjhub.com/#/issues/9594
*/
@Deprecated
public abstract void replaceStorage(final OStorage storage);
示例12
@Override
public void onStorageRegistered(OStorage storage) {
}
示例13
@Override
public void onStorageUnregistered(OStorage storage) {
}