@Override public boolean apply(Cell input) { if (!input.isLive(tsMillis)) return false; // Don't do this. getTimeToLive() is a duration divorced from any particular clock. // For instance, if TTL=10 seconds, getTimeToLive() will have value 10 (not 10 + epoch seconds), and // this will always return false. //if (input instanceof ExpiringCell) // return tsSeconds < ((ExpiringCell)input).getTimeToLive(); return true; } }
@Override public Object getMetaData(Cell element, EntryMetaData meta) { switch (meta) { case TIMESTAMP: return element.timestamp(); case TTL: return ((element instanceof ExpiringCell) ? ((ExpiringCell) element).getTimeToLive() : 0); default: throw new UnsupportedOperationException("Unsupported meta data: " + meta); } } }
@Override public boolean apply(@Nullable Row row) { // The hasOnlyTombstones(x) call below ultimately calls Column.isMarkedForDelete(x) return !(row == null || row.cf == null || row.cf.isMarkedForDelete() || row.cf.hasOnlyTombstones(nowMillis)); } });
ReadCommand cmd = new SliceFromReadCommand(CassandraUtils.keySpace, key, new ColumnParent(CassandraUtils.schemaInfoColumnFamily), startCol, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, pageSize); for(IColumn sc : row.cf.getSortedColumns()){ if(sc.name().equals(startCol)) continue; startCol = sc.name(); if(!sc.isLive()) continue; Integer id = Integer.valueOf(ByteBufferUtil.string(sc.name()));
public void deleteDocuments(String indexName, Term term, boolean autoCommit) throws CorruptIndexException, IOException { ColumnParent cp = new ColumnParent(CassandraUtils.termVecColumnFamily); ByteBuffer key = CassandraUtils.hashKeyBytes(indexName.getBytes("UTF-8"), CassandraUtils.delimeterBytes, term .field().getBytes("UTF-8"), CassandraUtils.delimeterBytes, term.text().getBytes("UTF-8")); ReadCommand rc = new SliceFromReadCommand(CassandraUtils.keySpace, key, cp, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, Integer.MAX_VALUE); List<Row> rows = CassandraUtils.robustRead(CassandraUtils.consistency, rc); // delete by documentId for (Row row : rows) { if (row.cf != null) { Collection<IColumn> columns = row.cf.getSortedColumns(); for (IColumn col : columns) { deleteLucandraDocument(indexName, CassandraUtils.readVInt(col.name()), autoCommit); } } } }
public static LucandraTermInfo[] convertTermInfo(Collection<IColumn> docs) { LucandraTermInfo termInfo[] = new LucandraTermInfo[docs.size()]; int i = 0; for (IColumn col : docs) { if (i == termInfo.length) break; if (i == 0 && col instanceof SuperColumn) throw new IllegalStateException( "TermInfo ColumnFamily is a of type Super: This is no longer supported, please see NEWS.txt"); if (col == null || col.name() == null || col.value() == null) throw new IllegalStateException("Encountered missing column: " + col); termInfo[i] = new LucandraTermInfo(CassandraUtils.readVInt(col.name()), col.value()); i++; } return termInfo; }
private static Collection<IColumn> getFieldCacheEntries(IndexReader indexReader, String field) throws IOException { String indexName = SolandraCoreContainer.coreInfo.get().indexName + "~" + SolandraCoreContainer.coreInfo.get().shard; byte[] indexNameBytes = indexName.getBytes("UTF-8"); if(logger.isDebugEnabled()) logger.debug("Loading field cache from " + indexName + " " + field); ColumnParent fieldCacheParent = new ColumnParent(CassandraUtils.fieldCacheColumnFamily); ByteBuffer fieldCacheKey = CassandraUtils.hashKeyBytes(indexNameBytes, CassandraUtils.delimeterBytes, field .getBytes()); List<Row> rows = CassandraUtils.robustRead(CassandraUtils.consistency, new SliceFromReadCommand( CassandraUtils.keySpace, fieldCacheKey, fieldCacheParent, ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, Integer.MAX_VALUE)); if (rows.isEmpty()) return Collections.emptyList(); Row row = rows.get(0); if (row.cf == null) return Collections.emptyList(); return row.cf.getSortedColumns(); }
@Override public boolean apply(@Nullable Row row) { return row != null && !row.key.getKey().equals(exceptKey); } });
@Override public ByteBuffer getValue(Cell element) { return org.apache.cassandra.utils.ByteBufferUtil.clone(element.value()); }
public void flush(String core) throws IOException { // Make sure all writes are in for this core writer.commit(core, true); ByteBuffer cacheKey = CassandraUtils.hashKeyBytes((core).getBytes("UTF-8"), CassandraUtils.delimeterBytes, "cache".getBytes("UTF-8")); RowMutation rm = new RowMutation(CassandraUtils.keySpace, cacheKey); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, CassandraUtils.cachedColBytes, CassandraUtils.cachedColBytes), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis()); CassandraUtils.robustInsert(ConsistencyLevel.QUORUM, rm); // also directly notify the local readers SolandraComponent.cacheCheck.put(core, System.currentTimeMillis() - CassandraUtils.cacheInvalidationInterval - 1); }
@Override public ByteBuffer getColumn(Cell element) { return org.apache.cassandra.utils.ByteBufferUtil.clone(element.name().toByteBuffer()); }
List<Row> rows = CassandraUtils.robustRead(keyKey, new QueryPath(CassandraUtils.schemaInfoColumnFamily, CassandraUtils.cachedColBytes), Arrays .asList(CassandraUtils.cachedColBytes), ConsistencyLevel.QUORUM); rows.get(0).cf.getColumn(CassandraUtils.cachedColBytes).getSubColumn(CassandraUtils.cachedColBytes).timestamp() >= lastCheck)
/** * You must do the compaction before running this to remove the duplicate tokens out of the * server. TODO code it. */ @SuppressWarnings("unchecked") public JSONObject estimateKeys() throws JSONException { Iterator<Entry<String, ColumnFamilyStoreMBean>> it = super.getColumnFamilyStoreMBeanProxies(); JSONObject object = new JSONObject(); while (it.hasNext()) { Entry<String, ColumnFamilyStoreMBean> entry = it.next(); object.put("keyspace", entry.getKey()); object.put("column_family", entry.getValue().getColumnFamilyName()); object.put("estimated_size", entry.getValue().estimateKeys()); } return object; }
public static List<Row> robustRead(ByteBuffer key, QueryPath qp, List<ByteBuffer> columns, ConsistencyLevel cl) throws IOException { ReadCommand rc = new SliceByNamesReadCommand(CassandraUtils.keySpace, key, qp, columns); return robustRead(cl, rc); }
public void refresh(List<String> keyspaces) throws IOException, ExecutionException, InterruptedException { Iterator<Entry<String, ColumnFamilyStoreMBean>> it = super.getColumnFamilyStoreMBeanProxies(); while (it.hasNext()) { Entry<String, ColumnFamilyStoreMBean> entry = it.next(); if (keyspaces.contains(entry.getKey())) { logger.info( "Refreshing {} {}", entry.getKey(), entry.getValue().getColumnFamilyName()); loadNewSSTables(entry.getKey(), entry.getValue().getColumnFamilyName()); } } }
@Override public void collect(int docNumber) throws IOException { deleteLucandraDocument(indexName, docNumber, autoCommit); numRemoved.incrementAndGet(); //delete the id reference rm.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, ByteBufferUtil.bytes(Integer.toString(docNumber))), System.currentTimeMillis()-1); }
private CLevel() { db = org.apache.cassandra.db.ConsistencyLevel.valueOf(toString()); thrift = org.apache.cassandra.thrift.ConsistencyLevel.valueOf(toString()); astyanax = com.netflix.astyanax.model.ConsistencyLevel.valueOf("CL_" + toString()); }
@Override public org.apache.cassandra.db.DecoratedKey<BigIntegerToken> decorateKey(ByteBuffer key) { ByteBuffer extractedToken = extractSolandraToken(key); //non-solandra key passes through if(extractedToken == null) return new org.apache.cassandra.db.DecoratedKey<BigIntegerToken>(super.getToken(key), key); //the token is pre-processed try { return new org.apache.cassandra.db.DecoratedKey<BigIntegerToken>(new BigIntegerToken(ByteBufferUtil.string(extractedToken)), key); } catch (CharacterCodingException e) { throw new RuntimeException(e); } }
@Override protected Object createValue(IndexReader reader, Entry entryKey) throws IOException { String field = StringHelper.intern(entryKey.field); final String[] retArray = new String[reader.maxDoc()]; Collection<IColumn> fcEntries = getFieldCacheEntries(reader, field); for (IColumn col : fcEntries) { if (col instanceof DeletedColumn) continue; int docId = CassandraUtils.readVInt(col.name()); String val = ByteBufferUtil.string(col.value()); retArray[docId] = val; } return retArray; } }
@Override public StaticBuffer next() { ensureOpen(); if (!hasNext()) throw new NoSuchElementException(); currentRow = keys.next(); ByteBuffer currentKey = currentRow.key.getKey().duplicate(); try { return StaticArrayBuffer.of(currentKey); } finally { lastSeenKey = currentKey; } }