com.orientechnologies.orient.core.storage.OStorage Java Examples

The following examples show how to use com.orientechnologies.orient.core.storage.OStorage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabasePoolSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #2
Source File: DatabasePoolSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #3
Source File: ConflictHook.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: DatabaseManagerSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void replaceStorage(final OStorage storage) {
  DatabasePoolSupport pool;
  synchronized (pools) {
    pool = pools.get(storage.getName());
  }
  if (pool != null) {
    pool.replaceStorage(storage);
  }
}
 
Example #5
Source File: DatabasePoolWithOverflowImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void replaceStorage(final OStorage storage) {
  try {
    replaceStorage(delegate, storage);
  }
  finally {
    replaceStorage(overflow, storage);
  }
}
 
Example #6
Source File: ConflictHook.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #7
Source File: DatabasePoolImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void replaceStorage(final OStorage storage) {
  replaceStorage(delegate, storage);
}
 
Example #8
Source File: OClusterModel.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
private OStorage getStorage() {
    return ODatabaseRecordThreadLocal.instance().get().getDatabaseOwner().getStorage();
}
 
Example #9
Source File: ListOClustersModel.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
private OStorage getStorage() {
    return ODatabaseRecordThreadLocal.instance().get().getDatabaseOwner().getStorage();
}
 
Example #10
Source File: DatabaseManager.java    From nexus-public with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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);
 
Example #11
Source File: DatabasePoolSupport.java    From nexus-public with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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);
 
Example #12
Source File: OLuceneIndexManagerAbstract.java    From orientdb-lucene with Apache License 2.0 2 votes vote down vote up
@Override
public void onStorageRegistered(OStorage storage) {

}
 
Example #13
Source File: OLuceneIndexManagerAbstract.java    From orientdb-lucene with Apache License 2.0 2 votes vote down vote up
@Override
public void onStorageUnregistered(OStorage storage) {

}