Package com.orientechnologies.orient.core.storage

Examples of com.orientechnologies.orient.core.storage.OCluster


  @Override
  public OCluster getClusterByName(final String iClusterName) {
    final boolean locked = lock.acquireSharedLock();

    try {
      final OCluster cluster = clusterMap.get(iClusterName.toLowerCase());

      if (cluster == null)
        throw new IllegalArgumentException("Cluster " + iClusterName + " not exists");
      return cluster;
View Full Code Here


   * @return The id (physical position into the array) of the new cluster just created. First is 0.
   * @throws IOException
   * @throws IOException
   */
  private int createClusterFromConfig(final OStorageClusterConfiguration iConfig) throws IOException {
    OCluster cluster = clusterMap.get(iConfig.getName());

    if (cluster != null) {
      if (cluster instanceof OClusterLocal)
        // ALREADY CONFIGURED, JUST OVERWRITE CONFIG
        ((OClusterLocal) cluster).config = (OStorageSegmentConfiguration) iConfig;
View Full Code Here

  public boolean removeCluster(final int iClusterId) {
    final boolean locked = lock.acquireExclusiveLock();
    try {

      OCluster c = clusters.get(iClusterId);
      c.delete();
      clusters.set(iClusterId, null);

    } catch (IOException e) {
    } finally {
View Full Code Here

    final boolean locked = lock.acquireSharedLock();
    try {

      final long offset = data.createRecord(iContent);
      final OCluster cluster = getClusterById(iRid.clusterId);

      iRid.clusterPosition = cluster.addPhysicalPosition(0, offset, iRecordType);
      return iRid.clusterPosition;
    } catch (IOException e) {
      throw new OStorageException("Error on create record in cluster: " + iRid.clusterId, e);

    } finally {
View Full Code Here

  }

  public int updateRecord(final ORecordId iRid, final byte[] iContent, final int iVersion, final byte iRecordType) {
    final long timer = OProfiler.getInstance().startChrono();

    final OCluster cluster = getClusterById(iRid.clusterId);

    final boolean locked = lock.acquireSharedLock();
    try {
      OPhysicalPosition ppos = cluster.getPhysicalPosition(iRid.clusterPosition, new OPhysicalPosition());
      if (ppos == null)
        return -1;

      // MVCC TRANSACTION: CHECK IF VERSION IS THE SAME
      if (iVersion > -1 && ppos.version != iVersion)
View Full Code Here

  }

  public boolean deleteRecord(final ORecordId iRid, final int iVersion) {
    final long timer = OProfiler.getInstance().startChrono();

    final OCluster cluster = getClusterById(iRid.clusterId);

    final boolean locked = lock.acquireSharedLock();
    try {
      final OPhysicalPosition ppos = cluster.getPhysicalPosition(iRid.clusterPosition, new OPhysicalPosition());

      if (ppos == null)
        return false;

      // MVCC TRANSACTION: CHECK IF VERSION IS THE SAME
      if (iVersion > -1 && ppos.version != iVersion)
        throw new OConcurrentModificationException(
            "Can't update record #"
                + iRid
                + " because it was modified by another user in the meanwhile of current transaction. Use pessimistic locking instead of optimistic or simply re-execute the transaction");

      cluster.removePhysicalPosition(iRid.clusterPosition, null);
      data.deleteRecord(ppos.dataPosition);

      return true;

    } catch (IOException e) {
View Full Code Here

      OProfiler.getInstance().stopChrono("OStorageMemory.deleteRecord", timer);
    }
  }

  public long count(final int iClusterId) {
    final OCluster cluster = getClusterById(iClusterId);

    final boolean locked = lock.acquireSharedLock();
    try {
      return cluster.getEntries();

    } finally {
      lock.releaseSharedLock(locked);
    }
  }
View Full Code Here

      lock.releaseSharedLock(locked);
    }
  }

  public long[] getClusterDataRange(final int iClusterId) {
    final OCluster cluster = getClusterById(iClusterId);

    final boolean locked = lock.acquireSharedLock();
    try {

      return new long[] { cluster.getFirstEntryPosition(), cluster.getLastEntryPosition() };
    } catch (IOException e) {

      throw new OStorageException("Error on getting last entry position in cluster: " + iClusterId, e);
    } finally {
View Full Code Here

    if (txEntry.status != OTransactionEntry.DELETED && !txEntry.getRecord().isDirty())
      return;

    final ORecordId rid = (ORecordId) txEntry.getRecord().getIdentity();

    final OCluster cluster = txEntry.clusterName != null ? storage.getClusterByName(txEntry.clusterName) : storage
        .getClusterById(rid.clusterId);

    if (!(cluster instanceof OClusterLocal))
      // ONLY LOCAL CLUSTER ARE INVOLVED IN TX
      return;

    if (txEntry.getRecord() instanceof OTxListener)
      ((OTxListener) txEntry.getRecord()).onEvent(txEntry, OTxListener.EVENT.BEFORE_COMMIT);

    switch (txEntry.status) {
    case OTransactionEntry.LOADED:
      break;

    case OTransactionEntry.CREATED: {
      // CHECK 2 TIMES TO ASSURE THAT IT'S A CREATE OR AN UPDATE BASED ON RECURSIVE TO-STREAM METHOD
      byte[] stream = txEntry.getRecord().toStream();

      if (rid.isNew()) {
        if (iTx.getDatabase().callbackHooks(ORecordHook.TYPE.BEFORE_CREATE, txEntry.getRecord()))
          // RECORD CHANGED: RE-STREAM IT
          stream = txEntry.getRecord().toStream();

        rid.clusterId = cluster.getId();

        if (iUseLog)
          createRecord(iTx.getId(), cluster, rid, stream, txEntry.getRecord().getRecordType());
        else
          iTx.getDatabase().getStorage().createRecord(rid, stream, txEntry.getRecord().getRecordType());
View Full Code Here

   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (clusterName == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");

    OCluster cluster = ((OStorageEmbedded) database.getStorage()).getClusterByName(clusterName);

    final long recs = cluster.getEntries();

    try {
      cluster.truncate();
    } catch (IOException e) {
      throw new OCommandExecutionException("Error on executing command", e);
    }

    return recs;
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.storage.OCluster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.