FaxianZhao opened a new pull request #7675: [FLINK-8297] [flink-rocksdb] A plan 
store elements of ListState as multiple key-values in rocksdb
URL: https://github.com/apache/flink/pull/7675
 
 
   ## What is the purpose of the change
   
   Enable storing lists not fitting to memory per single key.
   
   
   ## Brief change log
   
   Ref from PR #5185.
   I draft RocksDBLargeListState, it inherit AbstractRocksDBMapState which is 
similar RocksDBMapState.
   Dual to AbstractRocksDBMapState and RocksDBListState implement the same 
interface InternalKvState, and they meet an java generics conflict. So I create 
an new interface InternalLargeListState, I think we can refine the interface 
hierarchy to resolve this issue.
   
   RocksDBLargeListState store values to KV structure. 
   We store the lexicographically max key as KV value in the default 
key(#KeyGroup#Key#Namespace).
   If the value is instance of StreamRecord, we treat its timestamp as a part 
of key, and itself as value. 
   **It will sort elements by timestamp instead of insertion order, but I think 
its behavior is acceptable. We can also involve TtlValue.**
   Otherwise, treat current timestamp(maybe proc time) as a part of key, and 
itself as value.
   
   The rocksdb store structure.
   ```
   -----------Key-------------------       --------------------Value---------
   #KeyGroup#Key#Namespace                 #KeyGroup#Key#Namespace#ts3 (max 
lexicographically key)  
   #KeyGroup#Key#Namespace#ts1          value1,value2,value3  
   #KeyGroup#Key#Namespace#ts2          value4  
   #KeyGroup#Key#Namespace#ts3          value5,value6  
   ```
   
   Advantage: 
   1. We can seek to the lexicographically max key, then reverse iterate the 
list. 
   2. We can iterate the values with the event time / proc time, it good at 
monotonous scenario. Like TimeEvictor.
   3. We could make RocksDBListState and RocksDBMapState also inherit 
AbstractRocksDBMapState.
   
   Disadvantage:
   1. We couldn't simple replace RocksDBListState as RocksDBLargeListState, 
because of the above interface's generics conflict.
   2. It will add 8 bytes cost to store extended timestamp in key part. 
   3. For the timestamp base elements, it will sort elements by timestamp 
instead of insertion order. This behavior is not algn with others ListState.
   4. If the values has the same timestamp, the behavior almost same as 
RocksDBListState. I have a solution for this, but have not implement it yet. We 
can add order suffix for each timestamp. Like below.
   
   ```
   -----------Key---------------------       --------------------Value---------
   #KeyGroup#Key#Namespace             #KeyGroup#Key#Namespace#ts3#2 (Max 
lexicographically key)
   #KeyGroup#Key#Namespace#ts1           3 (The values' count which has the 
same timestamp ts1)
   #KeyGroup#Key#Namespace#ts1#1       value1
   #KeyGroup#Key#Namespace#ts1#2       value2
   #KeyGroup#Key#Namespace#ts1#3       value3
   #KeyGroup#Key#Namespace#ts2           1
   #KeyGroup#Key#Namespace#ts2#1       value4
   #KeyGroup#Key#Namespace#ts3           2
   #KeyGroup#Key#Namespace#ts3#1       value5
   #KeyGroup#Key#Namespace#ts3#2       value6
   ```
   
   I have try to add a murmur3 hash in the key part to resolve timestamp 
conflict, but it will crash the element order.
   
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added test in KVStateRequestSerializerRocksDBTest, the behavior is same 
as KVStateRequestSerializerRocksDBTest#testListSerialization
     - Because of the class reference issue, added test in 
RocksDBStateBackendTest, but implement them in StateBackendTestBase. The test 
behavior ref from StateBackendTestBase.testListState**
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: yes
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Yarn/Mesos, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? JavaDocs

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to