/** * Creates a 'remote' batch - with all enclosed mutations in encoded form (as ByteBuffer instances) * * The mutations will always be encoded using the current messaging version. */ public static Batch createRemote(UUID id, long creationTime, Collection<ByteBuffer> mutations) { return new Batch(id, creationTime, Collections.<Mutation>emptyList(), mutations); }
public Batch deserialize(DataInputPlus in, int version) throws IOException { UUID id = UUIDSerializer.serializer.deserialize(in, version); long creationTime = in.readLong(); /* * If version doesn't match the current one, we cannot not just read the encoded mutations verbatim, * so we decode them instead, to deal with compatibility. */ return version == MessagingService.current_version ? createRemote(id, creationTime, readEncodedMutations(in)) : createLocal(id, creationTime, decodeMutations(in, version)); }
private static void syncWriteToBatchlog(Collection<Mutation> mutations, BatchlogEndpoints endpoints, UUID uuid, long queryStartNanoTime) throws WriteTimeoutException, WriteFailureException { WriteResponseHandler<?> handler = new WriteResponseHandler<>(endpoints.all, Collections.<InetAddress>emptyList(), endpoints.all.size() == 1 ? ConsistencyLevel.ONE : ConsistencyLevel.TWO, Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME), null, WriteType.BATCH_LOG, queryStartNanoTime); Batch batch = Batch.createLocal(uuid, FBUtilities.timestampMicros(), mutations); if (!endpoints.current.isEmpty()) syncWriteToBatchlog(handler, batch, endpoints.current); if (!endpoints.legacy.isEmpty()) LegacyBatchlogMigrator.syncWriteToBatchlog(handler, batch, endpoints.legacy); handler.get(); }
private static void syncWriteToBatchlog(WriteResponseHandler<?> handler, Batch batch, Collection<InetAddress> endpoints) throws WriteTimeoutException, WriteFailureException { MessageOut<Batch> message = new MessageOut<>(MessagingService.Verb.BATCH_STORE, batch, Batch.serializer); for (InetAddress target : endpoints) { logger.trace("Sending batchlog store request {} to {} for {} mutations", batch.id, target, batch.size()); if (canDoLocalRequest(target)) performLocally(Stage.MUTATION, Optional.empty(), () -> BatchlogManager.store(batch), handler); else MessagingService.instance().sendRR(message, target, handler); } }
public Batch deserialize(DataInputPlus in, int version) throws IOException { UUID id = UUIDSerializer.serializer.deserialize(in, version); long creationTime = in.readLong(); /* * If version doesn't match the current one, we cannot not just read the encoded mutations verbatim, * so we decode them instead, to deal with compatibility. */ return version == MessagingService.current_version ? createRemote(id, creationTime, readEncodedMutations(in)) : createLocal(id, creationTime, decodeMutations(in, version)); }
private static void syncWriteToBatchlog(Collection<Mutation> mutations, BatchlogEndpoints endpoints, UUID uuid, long queryStartNanoTime) throws WriteTimeoutException, WriteFailureException { WriteResponseHandler<?> handler = new WriteResponseHandler<>(endpoints.all, Collections.<InetAddress>emptyList(), endpoints.all.size() == 1 ? ConsistencyLevel.ONE : ConsistencyLevel.TWO, Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME), null, WriteType.BATCH_LOG, queryStartNanoTime); Batch batch = Batch.createLocal(uuid, FBUtilities.timestampMicros(), mutations); if (!endpoints.current.isEmpty()) syncWriteToBatchlog(handler, batch, endpoints.current); if (!endpoints.legacy.isEmpty()) LegacyBatchlogMigrator.syncWriteToBatchlog(handler, batch, endpoints.legacy); handler.get(); }
private static void syncWriteToBatchlog(WriteResponseHandler<?> handler, Batch batch, Collection<InetAddress> endpoints) throws WriteTimeoutException, WriteFailureException { MessageOut<Batch> message = new MessageOut<>(MessagingService.Verb.BATCH_STORE, batch, Batch.serializer); for (InetAddress target : endpoints) { logger.trace("Sending batchlog store request {} to {} for {} mutations", batch.id, target, batch.size()); if (canDoLocalRequest(target)) performLocally(Stage.MUTATION, Optional.empty(), () -> BatchlogManager.store(batch), handler); else MessagingService.instance().sendRR(message, target, handler); } }
public Batch deserialize(DataInputPlus in, int version) throws IOException { UUID id = UUIDSerializer.serializer.deserialize(in, version); long creationTime = in.readLong(); /* * If version doesn't match the current one, we cannot not just read the encoded mutations verbatim, * so we decode them instead, to deal with compatibility. */ return version == MessagingService.current_version ? createRemote(id, creationTime, readEncodedMutations(in)) : createLocal(id, creationTime, decodeMutations(in, version)); }
private static void syncWriteToBatchlog(Collection<Mutation> mutations, BatchlogEndpoints endpoints, UUID uuid, long queryStartNanoTime) throws WriteTimeoutException, WriteFailureException { WriteResponseHandler<?> handler = new WriteResponseHandler<>(endpoints.all, Collections.<InetAddress>emptyList(), endpoints.all.size() == 1 ? ConsistencyLevel.ONE : ConsistencyLevel.TWO, Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME), null, WriteType.BATCH_LOG, queryStartNanoTime); Batch batch = Batch.createLocal(uuid, FBUtilities.timestampMicros(), mutations); if (!endpoints.current.isEmpty()) syncWriteToBatchlog(handler, batch, endpoints.current); if (!endpoints.legacy.isEmpty()) LegacyBatchlogMigrator.syncWriteToBatchlog(handler, batch, endpoints.legacy); handler.get(); }
/** * Creates a 'remote' batch - with all enclosed mutations in encoded form (as ByteBuffer instances) * * The mutations will always be encoded using the current messaging version. */ public static Batch createRemote(UUID id, long creationTime, Collection<ByteBuffer> mutations) { return new Batch(id, creationTime, Collections.<Mutation>emptyList(), mutations); }
private static void syncWriteToBatchlog(WriteResponseHandler<?> handler, Batch batch, Collection<InetAddress> endpoints) throws WriteTimeoutException, WriteFailureException { MessageOut<Batch> message = new MessageOut<>(MessagingService.Verb.BATCH_STORE, batch, Batch.serializer); for (InetAddress target : endpoints) { logger.trace("Sending batchlog store request {} to {} for {} mutations", batch.id, target, batch.size()); if (canDoLocalRequest(target)) performLocally(Stage.MUTATION, Optional.empty(), () -> BatchlogManager.store(batch), handler); else MessagingService.instance().sendRR(message, target, handler); } }
private static boolean apply(UntypedResultSet.Row row, long counter) { UUID id = row.getUUID("id"); long timestamp = id.version() == 1 ? UUIDGen.unixTimestamp(id) : row.getLong("written_at"); int version = row.has("version") ? row.getInt("version") : MessagingService.VERSION_12; if (id.version() != 1) id = UUIDGen.getTimeUUID(timestamp, counter); logger.trace("Converting mutation at {}", timestamp); try (DataInputBuffer in = new DataInputBuffer(row.getBytes("data"), false)) { int numMutations = in.readInt(); List<Mutation> mutations = new ArrayList<>(numMutations); for (int i = 0; i < numMutations; i++) mutations.add(Mutation.serializer.deserialize(in, version)); BatchlogManager.store(Batch.createLocal(id, TimeUnit.MILLISECONDS.toMicros(timestamp), mutations)); return true; } catch (Throwable t) { logger.error("Failed to convert mutation {} at timestamp {}", id, timestamp, t); return false; } }
/** * Creates a 'remote' batch - with all enclosed mutations in encoded form (as ByteBuffer instances) * * The mutations will always be encoded using the current messaging version. */ public static Batch createRemote(UUID id, long creationTime, Collection<ByteBuffer> mutations) { return new Batch(id, creationTime, Collections.<Mutation>emptyList(), mutations); }
public static void syncWriteToBatchlog(WriteResponseHandler<?> handler, Batch batch, Collection<InetAddress> endpoints) throws WriteTimeoutException, WriteFailureException { for (InetAddress target : endpoints) { logger.trace("Sending legacy batchlog store request {} to {} for {} mutations", batch.id, target, batch.size()); int targetVersion = MessagingService.instance().getVersion(target); MessagingService.instance().sendRR(getStoreMutation(batch, targetVersion).createMessage(MessagingService.Verb.MUTATION), target, handler, false); } }
private static boolean apply(UntypedResultSet.Row row, long counter) { UUID id = row.getUUID("id"); long timestamp = id.version() == 1 ? UUIDGen.unixTimestamp(id) : row.getLong("written_at"); int version = row.has("version") ? row.getInt("version") : MessagingService.VERSION_12; if (id.version() != 1) id = UUIDGen.getTimeUUID(timestamp, counter); logger.trace("Converting mutation at {}", timestamp); try (DataInputBuffer in = new DataInputBuffer(row.getBytes("data"), false)) { int numMutations = in.readInt(); List<Mutation> mutations = new ArrayList<>(numMutations); for (int i = 0; i < numMutations; i++) mutations.add(Mutation.serializer.deserialize(in, version)); BatchlogManager.store(Batch.createLocal(id, TimeUnit.MILLISECONDS.toMicros(timestamp), mutations)); return true; } catch (Throwable t) { logger.error("Failed to convert mutation {} at timestamp {}", id, timestamp, t); return false; } }
/** * Creates a 'local' batch - with all enclosed mutations in decoded form (as Mutation instances) */ public static Batch createLocal(UUID id, long creationTime, Collection<Mutation> mutations) { return new Batch(id, creationTime, mutations, Collections.emptyList()); }
public static void syncWriteToBatchlog(WriteResponseHandler<?> handler, Batch batch, Collection<InetAddress> endpoints) throws WriteTimeoutException, WriteFailureException { for (InetAddress target : endpoints) { logger.trace("Sending legacy batchlog store request {} to {} for {} mutations", batch.id, target, batch.size()); int targetVersion = MessagingService.instance().getVersion(target); MessagingService.instance().sendRR(getStoreMutation(batch, targetVersion).createMessage(MessagingService.Verb.MUTATION), target, handler, false); } }
private static boolean apply(UntypedResultSet.Row row, long counter) { UUID id = row.getUUID("id"); long timestamp = id.version() == 1 ? UUIDGen.unixTimestamp(id) : row.getLong("written_at"); int version = row.has("version") ? row.getInt("version") : MessagingService.VERSION_12; if (id.version() != 1) id = UUIDGen.getTimeUUID(timestamp, counter); logger.trace("Converting mutation at {}", timestamp); try (DataInputBuffer in = new DataInputBuffer(row.getBytes("data"), false)) { int numMutations = in.readInt(); List<Mutation> mutations = new ArrayList<>(numMutations); for (int i = 0; i < numMutations; i++) mutations.add(Mutation.serializer.deserialize(in, version)); BatchlogManager.store(Batch.createLocal(id, TimeUnit.MILLISECONDS.toMicros(timestamp), mutations)); return true; } catch (Throwable t) { logger.error("Failed to convert mutation {} at timestamp {}", id, timestamp, t); return false; } }
/** * Creates a 'local' batch - with all enclosed mutations in decoded form (as Mutation instances) */ public static Batch createLocal(UUID id, long creationTime, Collection<Mutation> mutations) { return new Batch(id, creationTime, mutations, Collections.emptyList()); }
public static void syncWriteToBatchlog(WriteResponseHandler<?> handler, Batch batch, Collection<InetAddress> endpoints) throws WriteTimeoutException, WriteFailureException { for (InetAddress target : endpoints) { logger.trace("Sending legacy batchlog store request {} to {} for {} mutations", batch.id, target, batch.size()); int targetVersion = MessagingService.instance().getVersion(target); MessagingService.instance().sendRR(getStoreMutation(batch, targetVersion).createMessage(MessagingService.Verb.MUTATION), target, handler, false); } }