anishshri-db commented on code in PR #43961:
URL: https://github.com/apache/spark/pull/43961#discussion_r1432210084
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateStoreChangelog.scala:
##########
@@ -109,18 +119,94 @@ class StateStoreChangelogWriter(
}
}
+/**
+ * Write changes to the key value state store instance to a changelog file.
+ * There are 2 types of records, put and delete.
+ * A put record is written as: | key length | key content | value length |
value content |
+ * A delete record is written as: | key length | key content | -1 |
+ * Write an Int -1 to signal the end of file.
+ * The overall changelog format is: | put record | delete record | ... | put
record | -1 |
+ */
+class StateStoreChangelogWriterV1(
+ fm: CheckpointFileManager,
+ file: Path,
+ compressionCodec: CompressionCodec)
+ extends StateStoreChangelogWriter(fm, file, compressionCodec) {
+
+ override def put(key: Array[Byte], value: Array[Byte]): Unit = {
+ assert(compressedStream != null)
+ compressedStream.writeInt(key.size)
+ compressedStream.write(key)
+ compressedStream.writeInt(value.size)
+ compressedStream.write(value)
+ size += 1
+ }
+
+ override def delete(key: Array[Byte]): Unit = {
+ assert(compressedStream != null)
+ compressedStream.writeInt(key.size)
+ compressedStream.write(key)
+ // -1 in the value field means record deletion.
+ compressedStream.writeInt(-1)
+ size += 1
+ }
+}
/**
- * Read an iterator of change record from the changelog file.
- * A record is represented by ByteArrayPair(key: Array[Byte], value:
Array[Byte])
- * A put record is returned as a ByteArrayPair(key, value)
- * A delete record is return as a ByteArrayPair(key, null)
+ * Write changes to the key value state store instance to a changelog file.
+ * There are 2 types of records, put and delete.
+ * A put record is written as: | record type | key length
+ * | key content | value length | value content | col family name length |
col family name | -1 |
+ * A delete record is written as: | record type | key length | key content | -1
+ * | col family name length | col family name | -1 |
+ * Write an Int -1 to signal the end of file.
+ * The overall changelog format is: | put record | delete record | ... | put
record | -1 |
+ */
+class StateStoreChangelogWriterV2(
+ fm: CheckpointFileManager,
+ file: Path,
+ compressionCodec: CompressionCodec)
+ extends StateStoreChangelogWriter(fm, file, compressionCodec) {
+
+ override def put(key: Array[Byte], value: Array[Byte], colFamilyName:
String): Unit = {
+ assert(compressedStream != null)
+ compressedStream.writeInt(RecordType.PUT_RECORD.toString.getBytes.size)
Review Comment:
Updated this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]