com.netflix.astyanax.model.ColumnFamily Java Examples

The following examples show how to use com.netflix.astyanax.model.ColumnFamily. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlobPlacementFactory.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Override
public Placement newPlacement(String placement) throws ConnectionException {
    String[] parsed = PlacementUtil.parsePlacement(placement);
    String keyspaceName = parsed[0];
    String cfPrefix = parsed[1];

    CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName);
    if (keyspace == null) {
        throw new UnknownPlacementException(format(
                "Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement);
    }

    KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace();
    ColumnFamily<ByteBuffer,Composite> columnFamily = getColumnFamily(keyspaceDef, cfPrefix, "blob", placement,
            new SpecificCompositeSerializer(CompositeType.getInstance(Arrays.<AbstractType<?>>asList(
                    AsciiType.instance, IntegerType.instance))));

    return new BlobPlacement(placement, keyspace, columnFamily);
}
 
Example #2
Source File: DeltaPlacementFactory.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Override
public Placement newPlacement(String placement) throws ConnectionException {
    String[] parsed = PlacementUtil.parsePlacement(placement);
    String keyspaceName = parsed[0];
    String cfPrefix = parsed[1];

    CassandraKeyspace keyspace = _keyspaceMap.get(keyspaceName);
    if (keyspace == null) {
        throw new UnknownPlacementException(format(
                "Placement string refers to unknown or non-local Cassandra keyspace: %s", keyspaceName), placement);
    }

    KeyspaceDefinition keyspaceDef = keyspace.getAstyanaxKeyspace().describeKeyspace();
    AnnotatedCompositeSerializer<DeltaKey> deltaKeySerializer  = new AnnotatedCompositeSerializer<DeltaKey>(DeltaKey.class);

    // DDL's are not actually configurable due to the way we abstract the names from the placements here.
    // In the future, we should either phase out the DDL config or change the implementation here to conform to it.
    ColumnFamily<ByteBuffer, DeltaKey> blockedDeltaCf = getColumnFamily(keyspaceDef, cfPrefix, "delta_v2", placement, deltaKeySerializer);
    ColumnFamily<ByteBuffer, UUID> deltaHistoryCf = getColumnFamily(keyspaceDef, cfPrefix, "history", placement, TimeUUIDSerializer.get());

    // Calculate the data centers on demand since they may change in a live system.
    return new DeltaPlacement(placement, keyspace, blockedDeltaCf, deltaHistoryCf);
}
 
Example #3
Source File: AstyanaxStoreManager.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public void clearStorage() throws BackendException {
    try {
        Cluster cluster = clusterContext.getClient();

        Keyspace ks = cluster.getKeyspace(keySpaceName);

        // Not a big deal if Keyspace doesn't not exist (dropped manually by user or tests).
        // This is called on per test setup basis to make sure that previous test cleaned
        // everything up, so first invocation would always fail as Keyspace doesn't yet exist.
        if (ks == null)
            return;

        for (ColumnFamilyDefinition cf : cluster.describeKeyspace(keySpaceName).getColumnFamilyList()) {
            ks.truncateColumnFamily(new ColumnFamily<Object, Object>(cf.getName(), null, null));
        }
    } catch (ConnectionException e) {
        throw new PermanentBackendException(e);
    }
}
 
Example #4
Source File: MetaDaoImpl.java    From staash with Apache License 2.0 6 votes vote down vote up
@Override
public void writeMetaEntity(Entity entity) {
    // TODO Auto-generated method stub
    Keyspace ks = kscp.acquireKeyspace("meta");
    ks.prepareMutationBatch();
    MutationBatch m;
    OperationResult<Void> result;
    m = ks.prepareMutationBatch();
    m.withRow(dbcf, entity.getRowKey()).putColumn(entity.getName(), entity.getPayLoad(), null);
    try {
        result = m.execute();
        if (entity instanceof PaasTableEntity) {
            String schemaName = ((PaasTableEntity)entity).getSchemaName();
            Keyspace schemaks = kscp.acquireKeyspace(schemaName);
            ColumnFamily<String, String> cf = ColumnFamily.newColumnFamily(entity.getName(), StringSerializer.get(), StringSerializer.get());
            schemaks.createColumnFamily(cf, null);
        }
        int i = 0;
    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
Example #5
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<? extends HistoryMigrationScanResult> getHistoriesForStorage(AstyanaxStorage source) {

    DeltaPlacement placement = (DeltaPlacement) source.getPlacement();
    ColumnFamily<ByteBuffer, UUID> cf = placement.getDeltaHistoryColumnFamily();

    return Iterators.concat(Iterators.transform(source.scanIterator(null), keyRange -> {
        Iterator<Row<ByteBuffer, UUID>> rows =
                rowScan(placement, cf, keyRange, _maxColumnsRange, LimitCounter.max(), ReadConsistency.STRONG);

        return Iterators.concat(Iterators.transform(rows, row -> {
            ColumnList<UUID> columns = row.getColumns();
            Iterator<Column<UUID>> concatColumns = columns.iterator();
            if (columns.size() >= _maxColumnsRange.getLimit()) {
                UUID lastColumn = row.getColumns().getColumnByIndex(columns.size() - 1).getName();
                concatColumns = Iterators.concat(concatColumns, columnScan(row.getRawKey(), placement, cf, lastColumn, null,
                        false, _uuidInc, Long.MAX_VALUE, 1, ReadConsistency.STRONG));
            }
            return Iterators.transform(concatColumns, column -> new HistoryMigrationScanResult(row.getRawKey(), column.getName(), column.getByteBufferValue(), column.getTtl()));
        }));
    }));
}
 
Example #6
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<? extends MigrationScanResult> getDeltasForStorage(AstyanaxStorage source) {
    DeltaPlacement sourcePlacement = (DeltaPlacement) source.getPlacement();
    ColumnFamily<ByteBuffer, DeltaKey> sourceCf = sourcePlacement.getBlockedDeltaColumnFamily();

    Iterator<ByteBufferRange> scanIter = source.scanIterator(null);

    return Iterators.concat(Iterators.transform(scanIter, keyRange -> {
        Iterator<Row<ByteBuffer, DeltaKey>> rows =
                rowScan(sourcePlacement, sourceCf, keyRange, _maxColumnsRange, LimitCounter.max(), ReadConsistency.STRONG);

        return Iterators.concat(Iterators.transform(rows, row -> {
            ColumnList<DeltaKey> columns = row.getColumns();
            Iterator<Column<DeltaKey>> concatColumns = columns.iterator();
            if (columns.size() >= _maxColumnsRange.getLimit()) {
                DeltaKey lastColumn = row.getColumns().getColumnByIndex(columns.size() - 1).getName();
                concatColumns = Iterators.concat(concatColumns, columnScan(row.getRawKey(), sourcePlacement, sourceCf, lastColumn, null,
                        false, _deltaKeyInc, Long.MAX_VALUE, 1, ReadConsistency.STRONG));
            }

            Iterator<StitchedColumn> uuidColumns = new AstyanaxDeltaIterator(concatColumns, false, _deltaPrefixLength, ByteBufferUtil.bytesToHex(row.getRawKey()));

            return Iterators.transform(uuidColumns, column -> new MigrationScanResult(row.getRawKey(), column.getName(), _daoUtils.skipPrefix(column.getByteBufferValue())));
        }));
    }));
}
 
Example #7
Source File: AstyanaxWriter.java    From blueflood with Apache License 2.0 6 votes vote down vote up
public void writeMetadata(Table<Locator, String, String> metaTable) throws ConnectionException {
    ColumnFamily cf = CassandraModel.CF_METRICS_METADATA;
    Timer.Context ctx = Instrumentation.getBatchWriteTimerContext(CassandraModel.CF_METRICS_METADATA_NAME);
    MutationBatch batch = keyspace.prepareMutationBatch();

    try {
        for (Locator locator : metaTable.rowKeySet()) {
            Map<String, String> metaRow = metaTable.row(locator);
            ColumnListMutation<String> mutation = batch.withRow(cf, locator);

            for (Map.Entry<String, String> meta : metaRow.entrySet()) {
                mutation.putColumn(meta.getKey(), meta.getValue(), StringMetadataSerializer.get(), null);
            }
        }
        try {
            batch.execute();
        } catch (ConnectionException e) {
            Instrumentation.markWriteError(e);
            log.error("Connection exception persisting metadata", e);
            throw e;
        }
    } finally {
        ctx.stop();
    }
}
 
Example #8
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 6 votes vote down vote up
private List<CfSplit> getCfSplits(Table tbl, int desiredRecordsPerSplit, @Nullable String fromKey) {
    checkNotNull(tbl, "table");

    AstyanaxTable table = (AstyanaxTable) tbl;
    AstyanaxStorage storage = table.getReadStorage();
    DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
    Keyspace keyspace = placement.getKeyspace().getAstyanaxKeyspace();
    ColumnFamily<ByteBuffer, DeltaKey> cf = placement.getBlockedDeltaColumnFamily();

    // Create at least one split per shard, perhaps more if a shard is large.
    List<CfSplit> splits = Lists.newArrayList();
    Iterator<ByteBufferRange> it = storage.scanIterator(fromKey);
    Collection<TokenRange> allTokenRanges = describeCassandraTopology(keyspace).values();
    while (it.hasNext()) {
        ByteBufferRange keyRange = it.next();

        String start = toTokenString(keyRange.getStart());
        String end = toTokenString(keyRange.getEnd());

        splits.addAll(getCfSplits(keyspace, cf, start, end, desiredRecordsPerSplit, allTokenRanges));
    }
    return splits;
}
 
Example #9
Source File: EntityCollectionManagerImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public Health getHealth() {

    try {
        ColumnFamily<String, String> CF_SYSTEM_LOCAL =
            new ColumnFamily<String, String>( "system.local", StringSerializer.get(), StringSerializer.get(),
                StringSerializer.get() );

        OperationResult<CqlResult<String, String>> result =
            keyspace.prepareQuery( CF_SYSTEM_LOCAL )
                .setConsistencyLevel(ConsistencyLevel.CL_ONE)
                .withCql( "SELECT now() FROM system.local;" )
                .execute();

        if ( result.getResult().getRows().size() > 0 ) {
            return Health.GREEN;
        }
    }
    catch ( ConnectionException ex ) {
        logger.error( "Error connecting to Cassandra", ex );
    }

    return Health.RED;
}
 
Example #10
Source File: AbstractPlacementFactory.java    From emodb with Apache License 2.0 6 votes vote down vote up
protected <C> ColumnFamily<ByteBuffer, C> getColumnFamily(KeyspaceDefinition keyspaceDef,
                                                          String prefix, String suffix, String placement,
                                                          Serializer<C> columnSerializer) throws IllegalArgumentException {
    // Create the column family object.  It must be keyed by a ByteBuffer because that's what
    // the AstyanaxTable.getRowKey() method returns.
    ColumnFamily<ByteBuffer, C> cf = new ColumnFamily<>(prefix + "_" + suffix,
            ByteBufferSerializer.get(), columnSerializer);

    // Verify that the column family exists in the Cassandra schema.
    ColumnFamilyDefinition cfDef = keyspaceDef.getColumnFamily(cf.getName());
    if (cfDef == null) {
        throw new UnknownPlacementException(format(
                "Placement string '%s' refers to unknown Cassandra %s column family in keyspace '%s': %s",
                placement, suffix, keyspaceDef.getName(), cf.getName()), placement);
    }
    return cf;
}
 
Example #11
Source File: MultiRowShardColumnIterator.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public MultiRowShardColumnIterator( final Keyspace keyspace, final ColumnFamily<R, C> cf,
                                    final ConsistencyLevel consistencyLevel, final ColumnParser<C, T> columnParser,
                                    final ColumnSearch<T> columnSearch, final Comparator<T> comparator,
                                    final int pageSize, final List<SmartShard> rowKeysWithShardEnd,
                                    final boolean ascending, final Optional<Long> lastTimestamp) {
    this.cf = cf;
    this.pageSize = pageSize;
    this.columnParser = columnParser;
    this.columnSearch = columnSearch;
    this.comparator = comparator;
    this.keyspace = keyspace;
    this.consistencyLevel = consistencyLevel;
    this.moreToReturn = true;
    this.rowKeysWithShardEnd = rowKeysWithShardEnd;
    this.resultsTracking = new ArrayList<>();
    this.ascending = ascending;
    this.lastTimestamp = lastTimestamp;


}
 
Example #12
Source File: MultiRowColumnIterator.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * Create the iterator
 */
public MultiRowColumnIterator( final Keyspace keyspace, final ColumnFamily<R, C> cf,
                               final ConsistencyLevel consistencyLevel, final ColumnParser<C, T> columnParser,
                               final ColumnSearch<T> columnSearch, final Comparator<T> comparator,
                               final Collection<R> rowKeys, final int pageSize ) {
    this.cf = cf;
    this.pageSize = pageSize;
    this.columnParser = columnParser;
    this.columnSearch = columnSearch;
    this.comparator = comparator;
    this.rowKeys = rowKeys;
    this.keyspace = keyspace;
    this.consistencyLevel = consistencyLevel;
    this.moreToReturn = true;

    //        seenResults = new HashMap<>( pageSize * 10 );
}
 
Example #13
Source File: V003.java    From mutagen-cassandra with Apache License 2.0 6 votes vote down vote up
@Override
protected void performMutation(Context context) {
	context.debug("Executing mutation {}",state.getID());
	final ColumnFamily<String,String> CF_TEST1=
		ColumnFamily.newColumnFamily("Test1",
			StringSerializer.get(),StringSerializer.get());

	MutationBatch batch=getKeyspace().prepareMutationBatch();
	batch.withRow(CF_TEST1,"row2")
		.putColumn("value1","chicken")
		.putColumn("value2","sneeze");

	try {
		batch.execute();
	}
	catch (ConnectionException e) {
		throw new MutagenException("Could not update columnfamily Test1",e);
	}
}
 
Example #14
Source File: MultiTenantColumnFamilyDefinition.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public MultiTenantColumnFamilyDefinition(final ColumnFamily columnFamily, final String keyValidationType,
                                         final String columnComparatorType, final String columnValidationType, final CacheOption cacheOption ) {

    Preconditions.checkNotNull( columnFamily, "columnFamily is required" );
    Preconditions.checkNotNull( columnComparatorType, "columnComparatorType is required" );
    Preconditions.checkNotNull( keyValidationType, "keyValidationType is required" );
    Preconditions.checkNotNull( columnValidationType, "columnValueValidationType is required" );
    Preconditions.checkNotNull( cacheOption, "cacheOption is required" );

    this.columnFamily = columnFamily;
    this.columnComparatorType = columnComparatorType;
    this.keyValidationType = keyValidationType;
    this.columnValidationType = columnValidationType;
    this.cacheOption = cacheOption;
}
 
Example #15
Source File: AstyanaxLockManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private ColumnFamily getLocksColumnFamily() {

        if ( columnFamily == null ) {

            columnFamily = ColumnFamily.newColumnFamily(
                CF_NAME, StringSerializer.get(), StringSerializer.get() );

            if ( logger.isDebugEnabled() ) {

                try {
                    final KeyspaceDefinition kd = keyspace.describeKeyspace();
                    final ColumnFamilyDefinition cfd = kd.getColumnFamily( columnFamily.getName() );
                    Map<String, Object> options = new HashMap<>( 1 );
                    options.put( "gc_grace_seconds", cfd.getGcGraceSeconds() );
                    options.put( "caching", cfd.getCaching() );
                    options.put( "compaction_strategy", cfd.getCompactionStrategy() );
                    options.put( "compaction_strategy_options", cfd.getCompactionStrategyOptions() );
                    logger.debug( "Locks column family {} exists with options: {}", cfd.getName(), options);

                } catch ( ConnectionException ce ) {
                    logger.warn("Error connecting to Cassandra for debug column family info", ce);
                }
            }
        }

        return columnFamily;
    }
 
Example #16
Source File: TestUtils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public static <K, C> void createColumnFamiliy(final Keyspace keyspace, final ColumnFamily<K, C> columnFamily, final Map<String, Object> options){
    try{

        if(keyspace.describeKeyspace().getColumnFamily(columnFamily.getName()) == null){
            keyspace.createColumnFamily( columnFamily, new HashMap<String, Object>() );
        }

    }catch(Exception e){
       logger.error( "Error on creating column family, ignoring" , e);
    }
}
 
Example #17
Source File: CassandraModel.java    From blueflood with Apache License 2.0 5 votes vote down vote up
public static Collection<String> getAllColumnFamiliesNames() {

        List<String> names = new ArrayList<String>() {{
                for (ColumnFamily cf : ALL_COLUMN_FAMILIES) {
                    add(cf.getName());
                }
        }};
        return names;
    }
 
Example #18
Source File: AstyanaxDao.java    From staash with Apache License 2.0 5 votes vote down vote up
public AstyanaxDao(Keyspace keyspace, Class<T> entityType, String columnFamilyName) {
    this.keyspace     = keyspace;
    this.entityName   = entityNameFromClass(entityType);
    this.columnFamily = new ColumnFamily<String, String>(columnFamilyName, StringSerializer.get(), StringSerializer.get());
    this.prefix       = this.entityName + ":";
    
    manager = new DefaultEntityManager.Builder<T, String>()
            .withKeyspace(keyspace)
            .withColumnFamily(columnFamily)
            .withEntityType(entityType)
            .build();
}
 
Example #19
Source File: AstyanaxDao.java    From staash with Apache License 2.0 5 votes vote down vote up
public AstyanaxDao(Keyspace keyspace, Class<T> entityType) {
    this.keyspace     = keyspace;
    this.entityName   = entityNameFromClass(entityType);
    this.columnFamily = new ColumnFamily<String, String>(this.entityName, StringSerializer.get(), StringSerializer.get());
    this.prefix       = "";
    
    manager = new DefaultEntityManager.Builder<T, String>()
            .withKeyspace(keyspace)
            .withColumnFamily(columnFamily)
            .withEntityType(entityType)
            .build();
}
 
Example #20
Source File: CassandraMutagenImplTest.java    From mutagen-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 *
 *
 */
@Test
public void testData() throws Exception {

	final ColumnFamily<String,String> CF_TEST1=
		ColumnFamily.newColumnFamily("Test1",
			StringSerializer.get(),StringSerializer.get());

	ColumnList<String> columns;
	columns=keyspace.prepareQuery(CF_TEST1)
		.getKey("row1")
		.execute()
		.getResult();

	assertEquals("foo",columns.getStringValue("value1",null));
	assertEquals("bar",columns.getStringValue("value2",null));

	columns=keyspace.prepareQuery(CF_TEST1)
		.getKey("row2")
		.execute()
		.getResult();

	assertEquals("chicken",columns.getStringValue("value1",null));
	assertEquals("sneeze",columns.getStringValue("value2",null));

	columns=keyspace.prepareQuery(CF_TEST1)
		.getKey("row3")
		.execute()
		.getResult();

	assertEquals("bar",columns.getStringValue("value1",null));
	assertEquals("baz",columns.getStringValue("value2",null));
}
 
Example #21
Source File: QueryUtils.java    From staash with Apache License 2.0 5 votes vote down vote up
public static String formatQueryResult(CqlStatementResult rs, String cfname) {
    // TODO Auto-generated method stub
    String value = "";
    JsonObject response = new JsonObject();
    ColumnFamily<String, String> cf = ColumnFamily
            .newColumnFamily(cfname, StringSerializer.get(),
                    StringSerializer.get());
    Rows<String, String> rows = rs.getRows(cf);
    int rcount = 1;
    for (com.netflix.astyanax.model.Row<String, String> row : rows) {
        ColumnList<String> columns = row.getColumns();
        Collection<String> colnames = columns.getColumnNames();
        String rowStr = "";
        String colStr = "";
        if (colnames.contains("key") && colnames.contains("column1")) {
        	colStr = colStr + columns.getDateValue("column1", null).toGMTString();
        	rowStr = rowStr + columns.getStringValue("value", null); 
        	response.putString(colStr, rowStr);
        } else {
            JsonObject rowObj = new JsonObject();
         for (String colName:colnames) {
             //colStr = colStr+colname+",";
            value = columns.getStringValue(colName, null);
            //rowStr=rowStr+value+",";
            rowObj.putString(colName, value);
         }
         //rowobj.putString("columns", colStr);
         //rowobj.putString("values", rowStr);
         response.putObject(""+rcount++, rowObj);
        }
    }
    return response.toString();
    
}
 
Example #22
Source File: AstyanaxSupport.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
protected AstyanaxSample(Builder builder) {
    super(builder.clusterName, builder.hostname, builder.thriftPort);
    columnFamilyName = checkNotNull(builder.columnFamilyName, "columnFamilyName");
    sampleColumnFamily = new ColumnFamily<String, String>(
            columnFamilyName, // Column Family Name
            StringSerializer.get(), // Key Serializer
            StringSerializer.get()); // Column Serializer
}
 
Example #23
Source File: AbstractCassandraHystrixCommand.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * returns a ColumnFamily given a columnFamilyName
 * @param columnFamilyName
 * @param rowKeyClass
 * @return a constructed ColumnFamily
 */
@SuppressWarnings({"unchecked", "rawtypes"})
protected ColumnFamily getColumnFamilyViaColumnName(String columnFamilyName, Class rowKeyClass) {
    if (rowKeyClass == String.class) {
        return new ColumnFamily(columnFamilyName, StringSerializer.get(), StringSerializer.get());
    } else if (rowKeyClass == Integer.class) {
        return new ColumnFamily(columnFamilyName, IntegerSerializer.get(), StringSerializer.get());
    } else if (rowKeyClass == Long.class) {
        return new ColumnFamily(columnFamilyName, LongSerializer.get(), StringSerializer.get());
    } else {
        throw new IllegalArgumentException("RowKeyType is not supported: " + rowKeyClass.getSimpleName() + ". String/Integer/Long are supported, or you can define the ColumnFamily yourself and use the other constructor.");
    }
}
 
Example #24
Source File: AstyanaxHistoryBatchPersister.java    From emodb with Apache License 2.0 5 votes vote down vote up
private AstyanaxHistoryBatchPersister(MutationBatch mutation, ColumnFamily<ByteBuffer, UUID> columnFamily,
                                      ChangeEncoder changeEncoder, HistoryStore historyStore) {
    _mutation = checkNotNull(mutation);
    _columnFamily = checkNotNull(columnFamily);
    _changeEncoder = checkNotNull(changeEncoder);
    _historyStore = checkNotNull(historyStore);
}
 
Example #25
Source File: BlobPlacement.java    From emodb with Apache License 2.0 5 votes vote down vote up
BlobPlacement(String name,
              CassandraKeyspace keyspace,
              ColumnFamily<ByteBuffer, Composite> blobColumnFamily) {
    _name = checkNotNull(name, "name");
    _keyspace = checkNotNull(keyspace, "keyspace");
    _blobColumnFamily = checkNotNull(blobColumnFamily, "blobColumnFamily");
}
 
Example #26
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Change> getExistingHistories(Key key, UUID start, UUID end, ReadConsistency consistency) {
    AstyanaxTable table = (AstyanaxTable) key.getTable();
    AstyanaxStorage storage = table.getReadStorage();
    ByteBuffer rowKey = storage.getRowKey(key.getKey());
    DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
    ColumnFamily<ByteBuffer, UUID> cf = placement.getDeltaHistoryColumnFamily();
    return decodeColumns(columnScan(rowKey, placement, cf, start, end, true, _uuidInc, MAX_COLUMN_SCAN_BATCH, 0, consistency));
}
 
Example #27
Source File: DeltaPlacement.java    From emodb with Apache License 2.0 5 votes vote down vote up
DeltaPlacement(String name,
               CassandraKeyspace keyspace,
               ColumnFamily<ByteBuffer, DeltaKey> blockedDeltaColumnFamily,
               ColumnFamily<ByteBuffer, UUID> deltaHistoryColumnFamily) {
    _name = checkNotNull(name, "name");
    _keyspace = checkNotNull(keyspace, "keyspace");
    _blockedDeltaColumnFamily = checkNotNull(blockedDeltaColumnFamily, "blockedDeltaColumnFamily");
    _deltaHistoryColumnFamily = checkNotNull(deltaHistoryColumnFamily, "deltaHistoryColumnFamily");

    _blockedDeltaTableDDL = createBlockedDeltaTableDDL(blockedDeltaColumnFamily.getName());
    _deltaHistoryTableDDL = creatHistoryTableDDL(_deltaHistoryColumnFamily.getName());
}
 
Example #28
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 5 votes vote down vote up
private Record newRecord(Key key, ByteBuffer rowKey, ColumnList<DeltaKey> columns, int largeRowThreshold, ReadConsistency consistency, @Nullable final Instant cutoffTime) {

        Iterator<Column<DeltaKey>> changeIter = getFilteredColumnIter(columns.iterator(), cutoffTime);
        Iterator<Column<DeltaKey>> compactionIter = getFilteredColumnIter(columns.iterator(), cutoffTime);
        Iterator<Column<DeltaKey>> rawMetadataIter = getFilteredColumnIter(columns.iterator(), cutoffTime);

        if (columns.size() >= largeRowThreshold) {
            // A large row such that the first query likely returned only a subset of all the columns.  Lazily fetch
            // the rest while ensuring we never load all columns into memory at the same time.  The current
            // Compactor+Resolver implementation must scan the row twice: once to find compaction records and once to
            // find deltas.  So we must call columnScan() twice, once for each.
            DeltaKey lastColumn = columns.getColumnByIndex(columns.size() - 1).getName();

            AstyanaxTable table = (AstyanaxTable) key.getTable();
            AstyanaxStorage storage = table.getReadStorage();
            DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
            ColumnFamily<ByteBuffer, DeltaKey> columnFamily = placement.getBlockedDeltaColumnFamily();

            // Execute the same scan 3 times, returning 3 iterators that process the results in different ways.  In
            // practice at most two of the iterators are actually consumed (one or more is ignored) so the columnScan
            // should avoid actually doing any work until the first item is fetched from the iterator.
            changeIter = Iterators.concat(changeIter,
                    getFilteredColumnIter(columnScan(rowKey, placement, columnFamily, lastColumn, null, false, _deltaKeyInc, Long.MAX_VALUE, 1, consistency), cutoffTime));
            compactionIter = Iterators.concat(compactionIter,
                    getFilteredColumnIter(columnScan(rowKey, placement, columnFamily, lastColumn, null, false, _deltaKeyInc, Long.MAX_VALUE, 1, consistency), cutoffTime));
            rawMetadataIter = Iterators.concat(rawMetadataIter,
                    getFilteredColumnIter(columnScan(rowKey, placement, columnFamily, lastColumn, null, false, _deltaKeyInc, Long.MAX_VALUE, 1, consistency), cutoffTime));
        }

        Iterator<Map.Entry<DeltaClusteringKey, Change>> deltaChangeIter = decodeChanges(new AstyanaxDeltaIterator(changeIter, false, _deltaPrefixLength, ByteBufferUtil.bytesToHex((rowKey))));
        Iterator<Map.Entry<DeltaClusteringKey, Compaction>> deltaCompactionIter = decodeCompactions(new AstyanaxDeltaIterator(compactionIter, false, _deltaPrefixLength, ByteBufferUtil.bytesToHex((rowKey))));
        Iterator<RecordEntryRawMetadata> deltaRawMetadataIter = rawMetadata(new AstyanaxDeltaIterator(rawMetadataIter, false, _deltaPrefixLength, ByteBufferUtil.bytesToHex((rowKey))));

        return new RecordImpl(key, deltaCompactionIter, deltaChangeIter, deltaRawMetadataIter);
    }
 
Example #29
Source File: AstyanaxBlockedDataReaderDAO.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Change> readTimeline(Key key, boolean includeContentData, UUID start, UUID end, boolean reversed,
                                     long limit, ReadConsistency consistency) {
    checkNotNull(key, "key");
    checkArgument(limit > 0, "Limit must be >0");
    checkNotNull(consistency, "consistency");

    AstyanaxTable table = (AstyanaxTable) key.getTable();
    AstyanaxStorage storage = table.getReadStorage();
    DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
    ByteBuffer rowKey = storage.getRowKey(key.getKey());

    // Read Delta and Compaction objects
    Iterator<Change> deltas = Iterators.emptyIterator();
    if (includeContentData) {
        ColumnFamily<ByteBuffer, DeltaKey> cf = placement.getBlockedDeltaColumnFamily();
        DeltaKey deltaStart = start != null ? new DeltaKey(start, 0) : null;
        DeltaKey deltaEnd = end != null ? new DeltaKey(end, Integer.MAX_VALUE) : null;
        deltas = decodeDeltaColumns(new LimitCounter(limit).limit(new AstyanaxDeltaIterator(columnScan(rowKey, placement, cf, deltaStart, deltaEnd, reversed, _deltaKeyInc, Long.MAX_VALUE, 0, consistency), reversed, _deltaPrefixLength, ByteBufferUtil.bytesToHex((rowKey)))));

    }

    // Read History objects
    Iterator<Change> deltaHistory = Iterators.emptyIterator();
    ColumnFamily<ByteBuffer, UUID> deltaHistoryCf = placement.getDeltaHistoryColumnFamily();
    deltaHistory = decodeColumns(columnScan(rowKey, placement, deltaHistoryCf, start, end, reversed, _uuidInc, limit, 0, consistency));

    return touch(MergeIterator.merge(deltas, deltaHistory, reversed));
}
 
Example #30
Source File: BatchUpdate.java    From emodb with Apache License 2.0 4 votes vote down vote up
public <K, C> Row<K, C> updateRow(ColumnFamily<K, C> columnFamily, K rowKey) {
    return updateRow(columnFamily, rowKey, null);
}