You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/08/07 12:30:44 UTC

[GitHub] GJL commented on a change in pull request #6510: [State TTL] Swap serialization order in TTL value: first timestamp then user value

GJL commented on a change in pull request #6510: [State TTL] Swap serialization order in TTL value: first timestamp then user value
URL: https://github.com/apache/flink/pull/6510#discussion_r208210641
 
 

 ##########
 File path: flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBMapState.java
 ##########
 @@ -625,4 +630,74 @@ private void loadCache() {
 			(Map<UK, UV>) stateDesc.getDefaultValue(),
 			backend);
 	}
+
+	/**
+	 * RocksDB map state specific byte value transformer wrapper.
+	 *
+	 * <p>This specific transformer wrapper checks the first byte to detect null user value entries
+	 * and if not null forward the rest of byte array to the original byte value transformer.
+	 */
+	static class StateSnapshotTransformerWrapper implements StateSnapshotTransformer<byte[]> {
+		private static final byte[] NULL_VALUE;
+		private static final byte NON_NULL_VALUE_PREFIX;
+		static {
+			ByteArrayDataOutputView dov = new ByteArrayDataOutputView(1);
+			try {
+				dov.writeBoolean(true);
+				NULL_VALUE = dov.toByteArray();
+				dov.reset();
+				dov.writeBoolean(false);
+				NON_NULL_VALUE_PREFIX = dov.toByteArray()[0];
+			} catch (IOException e) {
+				throw new FlinkRuntimeException("Failed to serialize boolean flag of map user null value", e);
+			}
+		}
+
+		private final StateSnapshotTransformer<byte[]> elementTransformer;
+		private final ByteArrayDataInputView div;
+
+		StateSnapshotTransformerWrapper(StateSnapshotTransformer<byte[]> originalTransformer) {
+			this.elementTransformer = originalTransformer;
+			this.div = new ByteArrayDataInputView();
+		}
+
+		@Override
+		@Nullable
+		public byte[] filterOrTransform(@Nullable byte[] value) {
+			if (value == null || isNull(value)) {
+				return NULL_VALUE;
+			} else {
+				// we have to skip the first byte indicating null user value
+				// TODO: optimization here cauld be to work with slices and not byte arrays
 
 Review comment:
   nit: *could*

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services