Пример #1
0
  boolean getMoreRelationships(NodeManager nodeManager) {
    // ArrayMap<String, IntArray> tmpRelMap = relationshipMap;
    Pair<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>> pair;
    synchronized (this) {
      if (!relChainPosition.hasMore()) {
        return false;
      }

      pair = nodeManager.getMoreRelationships(this);
      ArrayMap<String, RelIdArray> addMap = pair.first();
      if (addMap.size() == 0) {
        return false;
      }
      for (String type : addMap.keySet()) {
        RelIdArray addRels = addMap.get(type);
        // IntArray srcRels = tmpRelMap.get( type );
        RelIdArray srcRels = relationshipMap.get(type);
        if (srcRels == null) {
          relationshipMap.put(type, addRels);
        } else {
          srcRels.addAll(addRels);
        }
      }
    }
    nodeManager.putAllInRelCache(pair.other());
    return true;
  }
Пример #2
0
  @Override
  public void attemptWaitForTxCompletionAndBlockFutureTransactions(long maxWaitTimeMillis) {
    msgLog.logMessage("TxManager is blocking new transactions and waiting for active to fail...");
    blocked = true;
    List<Transaction> failedTransactions = new ArrayList<Transaction>();
    synchronized (txThreadMap) {
      for (Transaction tx : txThreadMap.values()) {
        try {
          int status = tx.getStatus();
          if (status != Status.STATUS_COMMITTING
              && status
                  != Status
                      .STATUS_ROLLING_BACK) { // Set it to rollback only if it's not committing or
                                              // rolling back
            tx.setRollbackOnly();
          }
        } catch (IllegalStateException e) { // OK
          failedTransactions.add(tx);
        } catch (SystemException e) { // OK
          failedTransactions.add(tx);
        }
      }
    }
    msgLog.logMessage(
        "TxManager blocked transactions"
            + ((failedTransactions.isEmpty()
                ? ""
                : ", but failed for: " + failedTransactions.toString())));

    long endTime = System.currentTimeMillis() + maxWaitTimeMillis;
    while (txThreadMap.size() > 0 && System.currentTimeMillis() < endTime) Thread.yield();
  }
Пример #3
0
 public void delete(NodeManager nodeManager) {
   nodeManager.acquireLock(this, LockType.WRITE);
   boolean success = false;
   try {
     ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this, true);
     ArrayMap<Integer, PropertyData> removedProps = nodeManager.deleteNode(this);
     if (removedProps.size() > 0) {
       for (int index : removedProps.keySet()) {
         skipMap.put(index, removedProps.get(index));
       }
     }
     success = true;
   } finally {
     nodeManager.releaseLock(this, LockType.WRITE);
     if (!success) {
       nodeManager.setRollbackOnly();
     }
   }
 }
Пример #4
0
  public void begin(ForceMode forceMode) throws NotSupportedException, SystemException {
    if (blocked) {
      throw new SystemException(
          "TxManager is preventing new transactions from starting " + "due a shutdown is imminent");
    }

    assertTmOk("tx begin");
    Thread thread = Thread.currentThread();
    TransactionImpl tx = txThreadMap.get(thread);
    if (tx != null) {
      throw logAndReturn(
          "TM error tx begin", new NotSupportedException("Nested transactions not supported"));
    }
    tx = new TransactionImpl(this, forceMode);
    txThreadMap.put(thread, tx);
    int concurrentTxCount = txThreadMap.size();
    if (concurrentTxCount > peakConcurrentTransactions) {
      peakConcurrentTransactions = concurrentTxCount;
    }
    startedTxCount.incrementAndGet();
    // start record written on resource enlistment
  }
Пример #5
0
 private Map<Long, RelationshipImpl> getMoreRelationships(
     NodeManager nodeManager, ArrayMap<String, RelIdArray> tmpRelMap) {
   if (!relChainPosition.hasMore()) {
     return null;
   }
   Pair<ArrayMap<String, RelIdArray>, Map<Long, RelationshipImpl>> pair =
       nodeManager.getMoreRelationships(this);
   ArrayMap<String, RelIdArray> addMap = pair.first();
   if (addMap.size() == 0) {
     return null;
   }
   for (String type : addMap.keySet()) {
     RelIdArray addRels = addMap.get(type);
     RelIdArray srcRels = tmpRelMap.get(type);
     if (srcRels == null) {
       tmpRelMap.put(type, addRels);
     } else {
       srcRels.addAll(addRels);
     }
   }
   return pair.other();
   // nodeManager.putAllInRelCache( pair.other() );
 }
Пример #6
0
 public int getActiveTxCount() {
   return txThreadMap.size();
 }
  public void delete() {
    NodeImpl startNode = null;
    NodeImpl endNode = null;
    boolean startNodeLocked = false;
    boolean endNodeLocked = false;
    nodeManager.acquireLock(this, LockType.WRITE);
    boolean success = false;
    try {
      startNode = nodeManager.getLightNode(startNodeId);
      if (startNode != null) {
        nodeManager.acquireLock(startNode, LockType.WRITE);
        startNodeLocked = true;
      }
      endNode = nodeManager.getLightNode(endNodeId);
      if (endNode != null) {
        nodeManager.acquireLock(endNode, LockType.WRITE);
        endNodeLocked = true;
      }
      // no need to load full relationship, all properties will be
      // deleted when relationship is deleted

      ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this, true);
      ArrayMap<Integer, PropertyData> removedProps = nodeManager.deleteRelationship(this);
      if (removedProps.size() > 0) {
        for (int index : removedProps.keySet()) {
          skipMap.put(index, removedProps.get(index));
        }
      }
      success = true;
      if (startNode != null) {
        startNode.removeRelationship(type, id);
      }
      if (endNode != null) {
        endNode.removeRelationship(type, id);
      }
      success = true;
    } finally {
      boolean releaseFailed = false;
      try {
        if (startNodeLocked) {
          nodeManager.releaseLock(startNode, LockType.WRITE);
        }
      } catch (Exception e) {
        releaseFailed = true;
        e.printStackTrace();
      }
      try {
        if (endNodeLocked) {
          nodeManager.releaseLock(endNode, LockType.WRITE);
        }
      } catch (Exception e) {
        releaseFailed = true;
        e.printStackTrace();
      }
      nodeManager.releaseLock(this, LockType.WRITE);
      if (!success) {
        setRollbackOnly();
      }
      if (releaseFailed) {
        throw new LockException(
            "Unable to release locks ["
                + startNode
                + ","
                + endNode
                + "] in relationship delete->"
                + this);
      }
    }
  }
Пример #8
0
 synchronized Object getTxLockElementCount() {
   return txLockElementMap.size();
 }