/**
   * Deletes documents from the activity engine
   *
   * @param uids
   */
  public void delete(long... uids) {
    boolean needToFlush = false;
    if (uids.length == 0) {
      return;
    }

    for (long uid : uids) {
      if (uid == Long.MIN_VALUE) {
        continue;
      }
      Lock writeLock = globalLock.writeLock();
      try {
        writeLock.lock();
        if (!uidToArrayIndex.containsKey(uid)) {
          continue;
        }
        deletedDocumentsCounter.inc();
        int index = uidToArrayIndex.remove(uid);
        for (ActivityValues activityIntValues : valuesMap.values()) {
          activityIntValues.delete(index);
        }
        needToFlush =
            needToFlush | pendingDeletes.addFieldUpdate(new Update(index, Long.MIN_VALUE));
      } finally {
        writeLock.unlock();
      }
    }
    if (needToFlush) {
      flush();
    }
  }
 public int getIndexByUID(long uid) {
   Lock lock = globalLock.readLock();
   try {
     lock.lock();
     if (!uidToArrayIndex.containsKey(uid)) {
       return -1;
     }
     return uidToArrayIndex.get(uid);
   } finally {
     lock.unlock();
   }
 }
 public int getIntValueByUID(long uid, String column) {
   Lock lock = globalLock.readLock();
   try {
     lock.lock();
     if (!uidToArrayIndex.containsKey(uid)) {
       return Integer.MIN_VALUE;
     }
     return ((ActivityIntValues) getActivityValues(column)).getIntValue(uidToArrayIndex.get(uid));
   } finally {
     lock.unlock();
   }
 }
  public int update(long uid, final String version, Map<String, Object> map) {
    if (valuesMap.isEmpty()) {
      return -1;
    }
    if (versionComparator.compare(lastVersion, version) > 0) {
      versionRejectionCounter.inc();
      return -1;
    }
    if (map.isEmpty()) {
      lastVersion = version;
      return -1;
    }
    int index = -1;

    Lock writeLock = globalLock.writeLock();
    boolean needToFlush = false;
    try {
      writeLock.lock();
      totalUpdatesCounter.inc();
      if (uidToArrayIndex.containsKey(uid)) {
        index = uidToArrayIndex.get(uid);
      } else {
        insertedDocumentsCounter.inc();
        synchronized (deletedIndexes) {
          if (deletedIndexes.size() > 0) {
            index = deletedIndexes.removeInt(deletedIndexes.size() - 1);
          } else {
            index = indexSize.getAndIncrement();
          }
        }
        uidToArrayIndex.put(uid, index);
        recentlyAddedUids.add(uid);
        needToFlush = updateBatch.addFieldUpdate(new Update(index, uid));
      }
      boolean currentUpdate = updateActivities(map, index);
      needToFlush = needToFlush || currentUpdate;
      lastVersion = version;
    } finally {
      writeLock.unlock();
    }
    if (needToFlush) {
      flush();
    }
    return index;
  }
 public int[] precomputeArrayIndexes(long[] uids) {
   int[] ret = new int[uids.length];
   for (int i = 0; i < uids.length; i++) {
     long uid = uids[i];
     if (uid == ZoieSegmentReader.DELETED_UID) {
       ret[i] = -1;
       continue;
     }
     Lock lock = globalLock.readLock();
     try {
       lock.lock();
       if (!uidToArrayIndex.containsKey(uid)) {
         ret[i] = -1;
       } else {
         ret[i] = uidToArrayIndex.get(uid);
       }
     } finally {
       lock.unlock();
     }
   }
   return ret;
 }
Ejemplo n.º 6
0
  public void expandVertex(
      Node target,
      TimeEntry removed,
      HashMap<Long, Integer> wasTraversed,
      PriorityQueue<TimeEntry> queue,
      HashMap<Long, RouteEntry> parents) {

    Long2IntMap neig = graph.accessNeighborhood(graph.getNode(removed.getId()));

    for (long vid : neig.keySet()) {

      int arrivalTime = graph.getArrival(removed.getArrivalTime(), neig.get(vid));
      int travelTime = removed.getTravelTime() + neig.get(vid);
      TimeEntry newEntry = new TimeEntry(vid, travelTime, arrivalTime, removed.getId());

      Edge edge = null;
      int distance = -1;

      if (!wasTraversed.containsKey(vid)) {

        queue.offer(newEntry);
        wasTraversed.put(newEntry.getId(), newEntry.getTravelTime());

        distance = neig.get(vid);
        edge = getEdge(removed.getId(), vid, distance);
        parents.put(
            vid, new RouteEntry(removed.getId(), distance / 17, edge.getId(), edge.getLabel()));
      } else {

        int cost = wasTraversed.get(vid);

        if (cost != wasRemoved && cost > newEntry.getTravelTime()) {
          queue.remove(newEntry);
          queue.offer(newEntry);
          wasTraversed.remove(newEntry.getId());
          wasTraversed.put(newEntry.getId(), newEntry.getTravelTime());

          parents.remove(vid);
          distance = neig.get(vid);
          edge = getEdge(removed.getId(), vid, distance);
          parents.put(
              vid, new RouteEntry(removed.getId(), distance / 17, edge.getId(), edge.getLabel()));
        }
      }
    }
  }