Пример #1
0
  public QueueIndexUpdate batchUpdateQueueIndex(
      QueueIndexUpdate indexUpdate, UUID subcriptionQueueId) throws Exception {

    logger.info("batchUpdateQueueIndex");

    Mutator<ByteBuffer> batch = indexUpdate.getBatch();

    // queue_id,prop_name
    Object index_key = key(subcriptionQueueId, indexUpdate.getEntryName());

    // subscription_queue_id,subscriber_queue_id,prop_name

    for (QueueIndexEntry entry : indexUpdate.getPrevEntries()) {

      if (entry.getValue() != null) {

        index_key = key(subcriptionQueueId, entry.getPath());

        batch.addDeletion(
            bytebuffer(index_key),
            PROPERTY_INDEX.getColumnFamily(),
            entry.getIndexComposite(),
            dce,
            indexUpdate.getTimestamp());
      } else {
        logger.error("Unexpected condition - deserialized property value is null");
      }
    }

    if (indexUpdate.getNewEntries().size() > 0) {

      for (QueueIndexEntry indexEntry : indexUpdate.getNewEntries()) {

        index_key = key(subcriptionQueueId, indexEntry.getPath());

        batch.addInsertion(
            bytebuffer(index_key),
            PROPERTY_INDEX.getColumnFamily(),
            createColumn(
                indexEntry.getIndexComposite(),
                ByteBuffer.allocate(0),
                indexUpdate.getTimestamp(),
                dce,
                be));
      }
    }

    for (String index : indexUpdate.getIndexesSet()) {
      batch.addInsertion(
          bytebuffer(key(subcriptionQueueId, DICTIONARY_SUBSCRIBER_INDEXES)),
          QUEUE_DICTIONARIES.getColumnFamily(),
          createColumn(index, ByteBuffer.allocate(0), indexUpdate.getTimestamp(), se, be));
    }

    return indexUpdate;
  }
Пример #2
0
  public QueueIndexUpdate batchStartQueueIndexUpdate(
      Mutator<ByteBuffer> batch,
      String queuePath,
      UUID queueId,
      String entryName,
      Object entryValue,
      UUID timestampUuid)
      throws Exception {

    long timestamp = getTimestampInMicros(timestampUuid);

    QueueIndexUpdate indexUpdate =
        new QueueIndexUpdate(batch, queuePath, queueId, entryName, entryValue, timestampUuid);

    List<HColumn<ByteBuffer, ByteBuffer>> entries = null;

    entries =
        createSliceQuery(cass.getApplicationKeyspace(applicationId), ue, be, be)
            .setColumnFamily(PROPERTY_INDEX_ENTRIES.getColumnFamily())
            .setKey(queueId)
            .setRange(
                DynamicComposite.toByteBuffer(entryName),
                setGreaterThanEqualityFlag(new DynamicComposite(entryName)).serialize(),
                false,
                INDEX_ENTRY_LIST_COUNT)
            .execute()
            .get()
            .getColumns();

    if (logger.isInfoEnabled()) {
      logger.info(
          "Found {} previous index entries for {} of entity {}",
          new Object[] {entries.size(), entryName, queueId});
    }

    // Delete all matching entries from entry list
    for (HColumn<ByteBuffer, ByteBuffer> entry : entries) {
      UUID prev_timestamp = null;
      Object prev_value = null;
      String prev_obj_path = null;

      // new format:
      // composite(entryName,
      // value_code,prev_value,prev_timestamp,prev_obj_path) = null
      DynamicComposite composite = DynamicComposite.fromByteBuffer(entry.getName().duplicate());
      prev_value = composite.get(2);
      prev_timestamp = (UUID) composite.get(3);
      if (composite.size() > 4) {
        prev_obj_path = (String) composite.get(4);
      }

      if (prev_value != null) {

        String entryPath = entryName;
        if ((prev_obj_path != null) && (prev_obj_path.length() > 0)) {
          entryPath = entryName + "." + prev_obj_path;
        }

        indexUpdate.addPrevEntry(entryPath, prev_value, prev_timestamp);

        // composite(property_value,subscriber_id,entry_timestamp)
        batch.addDeletion(
            bytebuffer(queueId),
            PROPERTY_INDEX_ENTRIES.getColumnFamily(),
            entry.getName().duplicate(),
            be,
            timestamp);
      } else {
        logger.error("Unexpected condition - deserialized property value is null");
      }
    }

    if (validIndexableValueOrJson(entryValue)) {

      List<Map.Entry<String, Object>> list = getKeyValueList(entryName, entryValue, false);

      for (Map.Entry<String, Object> indexEntry : list) {

        if (validIndexableValue(indexEntry.getValue())) {
          indexUpdate.addNewEntry(indexEntry.getKey(), toIndexableValue(indexEntry.getValue()));
        }
      }

      for (Map.Entry<String, Object> indexEntry : list) {

        String name = indexEntry.getKey();
        if (name.startsWith(entryName + ".")) {
          name = name.substring(entryName.length() + 1);
        } else if (name.startsWith(entryName)) {
          name = name.substring(entryName.length());
        }

        batch.addInsertion(
            bytebuffer(queueId),
            PROPERTY_INDEX_ENTRIES.getColumnFamily(),
            createColumn(
                DynamicComposite.toByteBuffer(
                    entryName,
                    indexValueCode(entryValue),
                    toIndexableValue(entryValue),
                    indexUpdate.getTimestampUuid(),
                    name),
                ByteBuffer.allocate(0),
                timestamp,
                be,
                be));

        indexUpdate.addIndex(indexEntry.getKey());
      }

      indexUpdate.addIndex(entryName);
    }

    return indexUpdate;
  }