/**
   * 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;
 }