snowflakedb / snowflake-ingest-java

Java SDK for the Snowflake Ingest Service -
http://www.snowflake.net
Apache License 2.0
71 stars 57 forks source link

SNOW-1814204 Use fair lock to ensure granting sequence #911

Closed sfc-gh-ggeng closed 22 hours ago

sfc-gh-ggeng commented 3 days ago

We should make sure that the long waiting thread get the lock. Otherwise, client’s later insertRow request with later offset token may come and get the lock first -- it will get the earlier internal continuation token and insert first. This could cause issues when incident happens and customer trying to replay the data. This may also cause the data ingested not in sequence.

We should use the fair synch lock to make sure that the thread with the longest waiting time (come earlier) wins and get the lock. Doc for the ReentrantLock: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReentrantLock.html