Package com.orientechnologies.orient.core.storage

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


  }

  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);

    lock.acquireSharedLock();
    try {

      lockManager.acquireLock(Thread.currentThread(), iRid, LOCK.EXCLUSIVE);
      try {

        final 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);

    lock.acquireSharedLock();
    try {

      lockManager.acquireLock(Thread.currentThread(), iRid, LOCK.EXCLUSIVE);
      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 delete record "
                  + iRid
                  + " because the version is not the latest one. Probably you are deleting an old record or it has been modified by another user (db=v"
                  + ppos.version + " your=v" + iVersion + ")");

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

        return true;

      } finally {
View Full Code Here

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

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

    lock.acquireSharedLock();
    try {

      return cluster.getEntries();

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

      lock.releaseSharedLock();
    }
  }

  public long[] getClusterDataRange(final int iClusterId) {
    final OCluster cluster = getClusterById(iClusterId);
    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 {
      lock.releaseSharedLock();
View Full Code Here

  private void commitEntry(final int iTxId, final OTransactionRecordEntry txEntry) throws IOException {

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

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

    switch (txEntry.status) {
    case OTransactionRecordEntry.LOADED:
      break;
View Full Code Here

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

    final OCluster cluster = getDatabase().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

      json.endCollection(1, true);
    }

    if (db.getClusterNames() != null) {
      json.beginCollection(1, false, "clusters");
      OCluster cluster;
      for (String clusterName : db.getClusterNames()) {
        cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));

        try {
          json.beginObject(2, true, null);
          json.writeAttribute(3, false, "id", cluster.getId());
          json.writeAttribute(3, false, "name", clusterName);
          json.writeAttribute(3, false, "records", cluster.getEntries() - cluster.getTombstonesCount());
          json.writeAttribute(3, false, "size", "-");
          json.writeAttribute(3, false, "filled", "-");
          json.writeAttribute(3, false, "maxSize", "-");
          json.writeAttribute(3, false, "files", "-");
        } catch (Exception e) {
View Full Code Here

      Collections.sort(clusters);

      for (String clusterName : clusters) {
        try {
          clusterId = currentDatabase.getClusterIdByName(clusterName);
          final OCluster cluster = currentDatabase.getStorage().getClusterById(clusterId);

          final String conflictStrategy = cluster.getRecordConflictStrategy() != null ? cluster.getRecordConflictStrategy()
              .getName() : "";

          count = currentDatabase.countClusterElements(clusterName);
          totalElements += count;
View Full Code Here

       json.endCollection(1, true);
     }

     if (db.getClusterNames() != null) {
       json.beginCollection(1, false, "clusters");
       OCluster cluster;
       for (String clusterName : db.getClusterNames()) {
         cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));

         try {
           json.beginObject(2, true, null);
           json.writeAttribute(3, false, "id", cluster.getId());
           json.writeAttribute(3, false, "name", clusterName);
           json.writeAttribute(3, false, "records", cluster.getEntries() - cluster.getTombstonesCount());
           json.writeAttribute(3, false, "size", "-");
           json.writeAttribute(3, false, "filled", "-");
           json.writeAttribute(3, false, "maxSize", "-");
           json.writeAttribute(3, false, "files", "-");
         } catch (Exception e) {
View Full Code Here

    super(url);
  }

  public void testMetadataStore() throws Exception {
    final int clusterId = database.addCluster("clusterTest");
    OCluster cluster = database.getStorage().getClusterById(clusterId);

    Assert.assertTrue(cluster.useWal());
    Assert.assertEquals(cluster.recordGrowFactor(), 1.2f);
    Assert.assertEquals(cluster.recordOverflowGrowFactor(), 1.2f);
    Assert.assertEquals(cluster.compression(), OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValueAsString());

    database.command(new OCommandSQL("alter cluster clusterTest use_wal false")).execute();
    database.command(new OCommandSQL("alter cluster clusterTest record_grow_factor 2")).execute();
    database.command(new OCommandSQL("alter cluster clusterTest record_overflow_grow_factor 2")).execute();
    database.command(new OCommandSQL("alter cluster clusterTest compression nothing")).execute();

    Assert.assertFalse(cluster.useWal());
    Assert.assertEquals(cluster.recordGrowFactor(), 2f);
    Assert.assertEquals(cluster.recordOverflowGrowFactor(), 2f);
    Assert.assertEquals(cluster.compression(), "nothing");

    OStorage storage = database.getStorage();
    database.close();
    storage.close(true, false);

    database.open("admin", "admin");

    cluster = database.getStorage().getClusterById(clusterId);
    Assert.assertFalse(cluster.useWal());
    Assert.assertEquals(cluster.recordGrowFactor(), 2f);
    Assert.assertEquals(cluster.recordOverflowGrowFactor(), 2f);
    Assert.assertEquals(cluster.compression(), "nothing");

    try {
      database.command(new OCommandSQL("alter cluster clusterTest record_grow_factor 0.5")).execute();
      Assert.fail();
    } catch (OException e) {
    }

    try {
      database.command(new OCommandSQL("alter cluster clusterTest record_grow_factor fff")).execute();
      Assert.fail();
    } catch (OException e) {
    }

    try {
      database.command(new OCommandSQL("alter cluster clusterTest record_overflow_grow_factor 0.5")).execute();
      Assert.fail();
    } catch (OException e) {
    }

    try {
      database.command(new OCommandSQL("alter cluster clusterTest record_overflow_grow_factor fff")).execute();
      Assert.fail();
    } catch (OException e) {
    }

    try {
      database.command(new OCommandSQL("alter cluster clusterTest compression dsgfgd")).execute();
      Assert.fail();
    } catch (OException e) {
    }

    Assert.assertFalse(cluster.useWal());
    Assert.assertEquals(cluster.recordGrowFactor(), 2f);
    Assert.assertEquals(cluster.recordOverflowGrowFactor(), 2f);
    Assert.assertEquals(cluster.compression(), "nothing");
  }
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.