Example usage for org.apache.cassandra.dht Token getTokenValue

List of usage examples for org.apache.cassandra.dht Token getTokenValue

Introduction

In this page you can find the example usage for org.apache.cassandra.dht Token getTokenValue.

Prototype

abstract public Object getTokenValue();

Source Link

Usage

From source file:com.stratio.cassandra.index.TokenMapperMurmur.java

License:Apache License

/** {@inheritDoc} */
@Override//from  w w w  .j  a v  a  2  s  . co  m
public Query query(Token token) {
    Long value = (Long) token.getTokenValue();
    return NumericRangeQuery.newLongRange(FIELD_NAME, value, value, true, true);
}

From source file:com.stratio.cassandra.index.TokenMapperMurmur.java

License:Apache License

/** {@inheritDoc} */
@Override/*from   w  w w .j  a va  2  s .  com*/
protected Query makeQuery(Token lower, Token upper, boolean includeLower, boolean includeUpper) {
    Long start = lower == null ? null : (Long) lower.getTokenValue();
    Long stop = upper == null ? null : (Long) upper.getTokenValue();
    if (lower != null && lower.isMinimum()) {
        start = null;
    }
    if (upper != null && upper.isMinimum()) {
        stop = null;
    }
    if (start == null && stop == null) {
        return null;
    }
    return NumericRangeQuery.newLongRange(FIELD_NAME, start, stop, includeLower, includeUpper);
}

From source file:com.stratio.cassandra.lucene.key.TokenMapper.java

License:Apache License

/**
 * Returns the {code Long} value of the specified Murmur3 partitioning {@link Token}.
 *
 * @param token a Murmur3 token/*from ww  w  .  ja  v  a 2  s .c om*/
 * @return the {@code token}'s {code Long} value
 */
public static Long value(Token token) {
    return (Long) token.getTokenValue();
}

From source file:org.elassandra.index.ExtendedElasticSecondaryIndex.java

License:Apache License

/**
 * cleans up deleted columns from cassandra cleanup compaction
 * @param key// w w  w .j  av  a2  s .c om
 */
@Override
@SuppressForbidden(reason = "unchecked")
public void delete(DecoratedKey key, Group opGroup) {
    if (!runsElassandra)
        return;

    if (mappingInfo == null || mappingInfo.indices.size() == 0) {
        // TODO: save the update in a commit log to replay it later....
        logger.warn("Elastic node not ready, cannot delete document");
        return;
    }

    Token token = key.getToken();
    Long token_long = (Long) token.getTokenValue();
    String typeName = InternalCassandraClusterService
            .cfNameToType(ExtendedElasticSecondaryIndex.this.baseCfs.metadata.cfName);

    // Delete documents where _token = token_long
    for (MappingInfo.IndexInfo indexInfo : this.mappingInfo.indices.values()) {
        if (logger.isTraceEnabled())
            logger.trace("deleting documents where _token={} from index.type={}.{} id={}", token_long,
                    indexInfo.name, typeName);
        IndexShard indexShard = indexInfo.indexService.shard(0);
        if (indexShard != null) {
            NumericRangeQuery<Long> query = NumericRangeQuery.newLongRange(TokenFieldMapper.NAME, token_long,
                    token_long, true, true);
            DeleteByQuery deleteByQuery = new DeleteByQuery(query, null, null, null, null,
                    Operation.Origin.PRIMARY, System.currentTimeMillis(), typeName);
            indexShard.engine().delete(deleteByQuery);
        }
    }
}

From source file:org.elasticsearch.cassandra.ElasticSecondaryIndex.java

License:Apache License

/**
 * cleans up deleted columns from cassandra cleanup compaction
 *
 * @param key//from www.  j av  a 2  s .  c  o m
 */
@Override
public void delete(DecoratedKey key, Group opGroup) {
    MappingInfo mappingInfo = this.mappingAtomicReference.get();
    if (mappingInfo == null || mappingInfo.indices.size() == 0) {
        // TODO: save the update in a commit log to replay it later....
        logger.warn("Elastic node not ready, cannot delete document");
        return;
    }
    Token token = key.getToken();
    Long token_long = (Long) token.getTokenValue();
    logger.debug("deleting (not imlemented) document with _token = " + token_long);

    // TODO: DeleteByQuery or Scan+Bulk Delete.
    /*
    for (Pair<String, String> target : targets.keySet()) {
    logger.debug("xdeleting document from index={} type={} id={}", target.left, target.right);
    // submit a delete request
    XDeleteRequest request = new XDeleteRequest(target.left, target.right, );
    ActionListener<XDeleteResponse> listener = new ActionListener<XDeleteResponse>() {
        @Override
        public void onResponse(XDeleteResponse response) {
            logger.debug("doc deleted id=" + response.getId());
        }
            
        @Override
        public void onFailure(Throwable e) {
            logger.error("failed to delete doc id=" + id, e);
        }
    };
    ElassandraDaemon.client().xdelete(request, listener);
    }
    */
}

From source file:org.elasticsearch.cassandra.index.ElasticSecondaryIndex.java

License:Apache License

/**
 * cleans up deleted columns from cassandra cleanup compaction
 *
 * @param key//from   ww  w  .j  a  v  a 2s.c  o  m
 */
@Override
public void delete(DecoratedKey key, Group opGroup) {
    MappingInfo mappingInfo = this.mappingAtomicReference.get();
    if (mappingInfo == null || mappingInfo.indices.size() == 0) {
        // TODO: save the update in a commit log to replay it later....
        logger.warn("Elastic node not ready, cannot delete document");
        return;
    }

    Token token = key.getToken();
    Long token_long = (Long) token.getTokenValue();
    logger.debug("deleting (not imlemented) document with _token = " + token_long);

    // TODO: DeleteByQuery or Scan+Bulk Delete.
    /*
    for (Pair<String, String> target : targets.keySet()) {
    logger.debug("xdeleting document from index={} type={} id={}", target.left, target.right);
    // submit a delete request
    XDeleteRequest request = new XDeleteRequest(target.left, target.right, );
    ActionListener<XDeleteResponse> listener = new ActionListener<XDeleteResponse>() {
        @Override
        public void onResponse(XDeleteResponse response) {
            logger.debug("doc deleted id=" + response.getId());
        }
            
        @Override
        public void onFailure(Throwable e) {
            logger.error("failed to delete doc id=" + id, e);
        }
    };
    ElassandraDaemon.client().xdelete(request, listener);
    }
    */
}