本文整理汇总了Java中com.netflix.astyanax.MutationBatch类的典型用法代码示例。如果您正苦于以下问题:Java MutationBatch类的具体用法?Java MutationBatch怎么用?Java MutationBatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MutationBatch类属于com.netflix.astyanax包,在下文中一共展示了MutationBatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
@Override
public void put(Buffer stream, Callback<Boolean> callback) {
MutationBatch m = keyspace.prepareMutationBatch();
BufferIterator it = stream.iterator();
while (it.hasNext()) {
Buffer keyView = it.next();
Buffer valueView = it.next();
if (valueView != null) {
m.withRow(MWG, keyView.data()).putColumn(0, valueView.data());
}
}
try {
@SuppressWarnings("unused")
OperationResult<Void> result = m.execute();
callback.on(true);
} catch (ConnectionException e) {
callback.on(false);
}
}
示例2: addPoint
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
public void addPoint(String key, List<SeriesValue> values) {
boolean nullKey = false;
try {
registerKey(key);
MutationBatch m = keyspace.prepareMutationBatch();
ColumnListMutation<String> mut = m.withRow(columnFamily, key);
for (SeriesValue value : values) {
if (value.getColumn() == null) nullKey = true;
else mut.putColumn(value.getColumn(), SeriesValueCodec.encodeValue(value), null);
}
m.execute();
} catch (ConnectionException ce) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("DbCommsError"), ce);
} catch (UnsupportedEncodingException e) {
throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, messageCatalog.getMessage("BadSeriesValue"), e);
}
if (nullKey) throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, messageCatalog.getMessage("BadKey"));
}
示例3: writeChunk
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
@ParameterizedTimed(type="AstyanaxStorageProvider")
@Override
public void writeChunk(Table tbl, String blobId, int chunkId, ByteBuffer data, Duration ttl, long timestamp) {
AstyanaxTable table = (AstyanaxTable) checkNotNull(tbl, "table");
for (AstyanaxStorage storage : table.getWriteStorage()) {
BlobPlacement placement = (BlobPlacement) storage.getPlacement();
// Write two columns: one small one and one big one with the binary data. Readers can query on
// the presence of the small one to be confident that the big column has replicated and is available.
MutationBatch mutation = placement.getKeyspace().prepareMutationBatch(CONSISTENCY_STRONG)
.setTimestamp(timestamp);
Integer ttlSeconds = Ttls.toSeconds(ttl, 1, null);
mutation.withRow(placement.getBlobColumnFamily(), storage.getRowKey(blobId))
.putEmptyColumn(getColumn(ColumnGroup.B, chunkId), ttlSeconds)
.putColumn(getColumn(ColumnGroup.Z, chunkId), data, ttlSeconds);
execute(mutation);
_blobWriteMeter.mark(data.remaining());
}
}
示例4: deleteOldColumns
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
private void deleteOldColumns(AstyanaxTable table, String blobId, ColumnList<Composite> columns, long timestamp) {
for (AstyanaxStorage storage : table.getWriteStorage()) {
BlobPlacement placement = (BlobPlacement) storage.getPlacement();
// Any columns with a timestamp older than the one we expect must be from an old version
// of the blob. This should be rare, but if it happens clean up and delete the old data.
MutationBatch mutation = placement.getKeyspace().prepareMutationBatch(ConsistencyLevel.CL_ANY);
ColumnListMutation<Composite> row = mutation.withRow(
placement.getBlobColumnFamily(), storage.getRowKey(blobId));
boolean found = false;
for (Column<Composite> column : columns) {
if (column.getTimestamp() < timestamp) {
if (ColumnGroup.B.name().equals(column.getName().get(0, AsciiSerializer.get()))) {
int chunkId = column.getName().get(1, IntegerSerializer.get());
row.deleteColumn(getColumn(ColumnGroup.B, chunkId))
.deleteColumn(getColumn(ColumnGroup.Z, chunkId));
found = true;
}
}
}
if (found) {
execute(mutation);
}
}
}
示例5: save
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
private void save(String channel, ByteBuffer slabId, boolean open, ConsistencyLevel consistency) {
MutationBatch mutation = _keyspace.prepareMutationBatch(consistency);
Duration ttl = getTtl(channel, open);
mutation.withRow(ColumnFamilies.MANIFEST, channel)
.putColumn(slabId, open, Ttls.toSeconds(ttl, 1, null));
// Readers check for the open slab marker to see if a slab is open and may not re-read the manifest open
// flag very often. So delete the open slab marker so readers notice the state change more quickly.
if (!open) {
mutation.withRow(ColumnFamilies.SLAB, slabId)
.deleteColumn(Constants.OPEN_SLAB_MARKER);
}
execute(mutation);
}
示例6: delete
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
@Override
public void delete(String channel, ByteBuffer slabId) {
// Deletes don't need to be durable. If a delete is lost, the next reader to come along and find no events
// will execute the delete again.
MutationBatch mutation = _keyspace.prepareMutationBatch(ConsistencyLevel.CL_ANY);
mutation.withRow(ColumnFamilies.MANIFEST, channel)
.deleteColumn(slabId);
mutation.withRow(ColumnFamilies.SLAB, slabId)
.delete();
execute(mutation);
_deleteMeter.mark();
}
示例7: purge
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
@Override
public void purge(AstyanaxStorage storage, Runnable progress) {
DeltaPlacement placement = (DeltaPlacement) storage.getPlacement();
CassandraKeyspace keyspace = placement.getKeyspace();
// Scan all the shards and delete all the rows we find.
MutationBatch mutation = keyspace.prepareMutationBatch(SorConsistencies.toAstyanax(WriteConsistency.STRONG));
Iterator<String> keyIter = _keyScanner.scanKeys(storage, ReadConsistency.STRONG);
while (keyIter.hasNext()) {
ByteBuffer rowKey = storage.getRowKey(keyIter.next());
mutation.withRow(placement.getDeltaColumnFamily(), rowKey).delete();
mutation.withRow(placement.getBlockedDeltaColumnFamily(), rowKey).delete();
mutation.withRow(placement.getAuditColumnFamily(), rowKey).delete();
if (mutation.getRowCount() >= 100) {
progress.run();
execute(mutation, "purge %d records from placement %s", mutation.getRowCount(), placement.getName());
mutation.discardMutations();
}
}
if (!mutation.isEmpty()) {
progress.run();
execute(mutation, "purge %d records from placement %s", mutation.getRowCount(), placement.getName());
}
}
示例8: remove
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
private void remove(Remove action, MetaLookup mgr, MutationBatch m) {
Info info = columnFamilies.fetchColumnFamilyInfo(action.getColFamily().getColumnFamily(), mgr);
if(info == null)
return; //if no cf exist/returned, nothing to do
ColumnFamily cf = info.getColumnFamilyObj();
switch(action.getAction()) {
case REMOVE_ENTIRE_ROW:
m.withRow(cf, action.getRowKey()).delete();
break;
case REMOVE_COLUMNS_FROM_ROW:
removeColumns(action, cf, m);
break;
default:
throw new RuntimeException("bug, unknown remove action="+action.getAction());
}
}
示例9: insertDataToDB
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
public void insertDataToDB(String rowKey, String entity, String category,
String sentiment, String time, String text, String count, String entityInfo, boolean isDynamicSearch) throws ConnectionException, InterruptedException, ExecutionException {
MutationBatch mb = GlobalVariables.KS_AST.prepareMutationBatch();//The mutator is not thread safe
ColumnFamily<String, String> CF_AST;
if (isDynamicSearch) {
CF_AST = CF_AST_DYNA;
} else {
CF_AST = CF_AST_BACK;
}
mb.withRow(CF_AST, rowKey)
.putColumn("entity", entity)
.putColumn("category", category)
.putColumn("sentiment", sentiment)
.putColumn("time", time)
.putColumn("text", text)
.putColumn("count", count)
.putColumn("entityInfo", entityInfo);
// no asynchronous feature
@SuppressWarnings("unused")
OperationResult<Void> result = mb.execute();
}
示例10: insertDataToDB_asynchronous
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
public void insertDataToDB_asynchronous(String rowKey, String entity, String category,
String sentiment, String time, String text, String count, String entityInfo, boolean isDynamicSearch)
throws ConnectionException, InterruptedException, ExecutionException {
MutationBatch mb = GlobalVariables.KS_AST.prepareMutationBatch();//The mutator is not thread safe
ColumnFamily<String, String> CF_AST;
if (isDynamicSearch) {
CF_AST = CF_AST_DYNA;
} else {
CF_AST = CF_AST_BACK;
}
mb.withRow(CF_AST, rowKey)
.putColumn("entity", entity)
.putColumn("category", category)
.putColumn("sentiment", sentiment)
.putColumn("time", time)
.putColumn("text", text)
.putColumn("count", count)
.putColumn("entityInfo", entityInfo);
// asynchronous feature
ListenableFuture<OperationResult<Void>> future = mb.executeAsync();
@SuppressWarnings("unused")
OperationResult<Void> result = future.get();
}
示例11: insertMovieDataToDB_asynchronous
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
public void insertMovieDataToDB_asynchronous(String rowKey, String movieName, String hybridRating, String count)
throws ConnectionException, InterruptedException, ExecutionException {
MutationBatch mb = GlobalVariables.KS_AST.prepareMutationBatch();//The mutator is not thread safe
ColumnFamily<String, String> CF_AST = CF_AST_BACK;
mb.withRow(CF_AST, rowKey)
.putColumn("movieName", movieName)
.putColumn("hybridRating", hybridRating)
.putColumn("count", count);
// asynchronous feature
ListenableFuture<OperationResult<Void>> future = mb.executeAsync();
@SuppressWarnings("unused")
OperationResult<Void> result = future.get();
}
示例12: executeBatch
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
private ListenableFuture<OperationResult<Void>> executeBatch(final List<Mutation> mutations, final Keyspace keyspace) {
final long startTime = System.nanoTime();
final MutationBatch batch = keyspace
.prepareMutationBatch()
.withAtomicBatch(false)
.withConsistencyLevel(ConsistencyLevel.CL_ONE);
for (Mutation aMutation : mutations) {
batch.withRow(DefaultModel.model, aMutation.getIdentity())
.putColumn(aMutation.getTimeStamp(), aMutation.getCommunication(), DefaultModel.valueSerializer, 0);
}
try {
final ListenableFuture<OperationResult<Void>> operationResultListenableFuture = batch.executeAsync();
operationResultListenableFuture.addListener(new OneShotTask(startTime), executorService);
} catch (ConnectionException e) {
logger.error("error inserting batch", e);
}
return null;
}
示例13: executeBatch
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
private long executeBatch(final List<Mutation> mutations) throws ConnectionException {
long startTime = System.nanoTime();
MutationBatch batch = keyspace
.prepareMutationBatch()
.withAtomicBatch(false)
.withConsistencyLevel(ConsistencyLevel.CL_ONE);
for (Mutation aMutation : mutations) {
batch.withRow(DefaultModel.model, aMutation.getIdentity())
.putColumn(aMutation.getTimeStamp(), aMutation.getCommunication(), DefaultModel.valueSerializer, 0);
}
try {
batch.execute();
} catch (ConnectionException e) {
logger.error("error inserting batch", e);
throw e;
}
long timeSpan = (System.nanoTime() - startTime);
return timeSpan;
}
示例14: createInstanceEntry
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
public void createInstanceEntry(RaigadInstance instance) throws Exception {
logger.info("Creating new instance entry");
String key = getRowKey(instance);
// If the key exists throw exception
if (getInstance(instance.getApp(), instance.getDC(), instance.getId()) != null) {
logger.info(String.format("Key already exists: %s", key));
return;
}
// Grab the lock
getLock(instance);
MutationBatch mutationBatch = bootKeyspace.prepareMutationBatch();
ColumnListMutation<String> columnListMutation = mutationBatch.withRow(CF_INSTANCES, key);
columnListMutation.putColumn(CN_CLUSTER, instance.getApp(), null);
columnListMutation.putColumn(CN_AZ, instance.getAvailabilityZone(), null);
columnListMutation.putColumn(CN_INSTANCEID, instance.getInstanceId(), null);
columnListMutation.putColumn(CN_HOSTNAME, instance.getHostName(), null);
columnListMutation.putColumn(CN_IP, instance.getHostIP(), null);
columnListMutation.putColumn(CN_LOCATION, instance.getDC(), null);
columnListMutation.putColumn(CN_ASGNAME, instance.getAsg(), null);
columnListMutation.putColumn(CN_UPDATETIME, TimeUUIDUtils.getUniqueTimeUUIDinMicros(), null);
mutationBatch.execute();
}
示例15: handleTuple
import com.netflix.astyanax.MutationBatch; //导入依赖的package包/类
@Override
public void handleTuple(ITuple tuple) {
MutationBatch m = keyspace.prepareMutationBatch();
if (! getProperties().containsKey(INCREMENT)){
m.withRow(new ColumnFamily((String) properties.get(COLUMN_FAMILY),
ByteBufferSerializer.get(),
ByteBufferSerializer.get()),
(ByteBuffer) tuple.getField(ROW_KEY))
.putColumn((ByteBuffer) tuple.getField(COLUMN), (ByteBuffer) tuple.getField(VALUE));
} else {
m.withRow(new ColumnFamily((String) properties.get(COLUMN_FAMILY),
ByteBufferSerializer.get(),
ByteBufferSerializer.get()),
(ByteBuffer) tuple.getField(ROW_KEY))
.incrementCounterColumn((ByteBuffer) tuple.getField(COLUMN),((Number) tuple.getField(VALUE) ).longValue());
}
try {
OperationResult<Void> result = m.execute();
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}