Yordan Pavlov created FLINK-41742:
-------------------------------------

             Summary: ForSt: a single failed remote file operation on a 
background thread breaks all later ForSt file I/O on that TaskManager until the 
JVM restarts
                 Key: FLINK-41742
                 URL: https://issues.apache.org/jira/browse/FLINK-41742
             Project: Flink
          Issue Type: Bug
          Components: Runtime / State Backends
    Affects Versions: 2.3.0, 2.2.0, 2.1.0, 2.0.0
            Reporter: Yordan Pavlov


When ForSt keeps its DB files on a remote file system (the default 
state.backend.forst.primary-dir = checkpoint dir, used by async State V2 
operators), one transient IOException from the Flink FileSystem, raised on a 
RocksDB background thread (flush/compaction), 
  leaves that thread permanently broken. Every later call into Java from that 
thread fails at once and reports the original exception again, without doing 
any I/O. RocksDB's background thread pool is process-wide, so the DB instances 
created when the job restores 
  reuse the same broken thread. The job then fails on every restart with

  {noformat}
  org.forstdb.RocksDBException: CallObjectMethod Exception when Init 
FlinkWritableFile, className: 
org/apache/flink/state/forst/fs/StringifiedForStFileSystem, methodName: create, 
... args: 
Path(s3://.../shared/op_AsyncKeyedProcessOperator_..._attempt_N/db/000055.sst)
  {noformat}

  while stderr keeps printing the *original* exception, always for the same 
object from the first attempt:

  {noformat}
  Exception in thread "Thread-13" 
org.apache.hadoop.fs.s3a.AWSBadRequestException: Writing Object on 
.../op_AsyncKeyedProcessOperator_..._attempt_0/db/3e7fa142-...: ... Status 
Code: 400 ...
  {noformat}

  Only restarting the TaskManager process recovers the job.

  *Root cause*

  env/flink/jni_helper.cc in ForSt, functions CurrentStatus() and 
CheckThenError(), which every JNI call in env_flink.cc goes through:

  {code:cpp}
  jthrowable throwable = jniEnv->ExceptionOccurred();
  jniEnv->ExceptionDescribe();
  jniEnv->ExceptionClear();
  jniEnv->Throw(throwable);   // "Throw Exception to Java side"
  return IOStatus::IOError(...);
  {code}
  
  Re-throwing is correct for a Java thread that called into native code: the 
exception is delivered when the native method returns. A RocksDB background 
thread has no Java caller, though. getJNIEnv() attaches it to the JVM once and 
keeps it attached for the thread's 
  lifetime, so the re-thrown exception stays pending forever. Making JNI calls 
with an exception pending is not allowed. In practice every later 
CallObjectMethod / CallVoidMethod on that thread returns with the old exception 
still pending. CurrentStatus() then prints
  it again, clears it and re-throws it, and the cycle continues.
 
  *Observed in production*
  
  Flink 2.3.0, forstjni 0.1.8, S3 (Hadoop S3A) as primary dir, one job using 
AsyncKeyedProcessOperator. A few-minute burst of HTTP 400s from the object 
store hit about 10 jobs on the cluster. Every job using RocksDB or heap state 
recovered on the next checkpoint. The
  ForSt job went into a restart loop (restore OK in about 4 s, then failure 
within seconds on the first flush) that lasted until the TaskManager pod was 
deleted. The same stale exception was printed 129+ times from the same thread.

  *Proposed fix*

  A PR to ververica/ForSt will follow. In CurrentStatus() / CheckThenError(), 
re-throw only when the current thread was not attached by ForSt itself (i.e. it 
has a Java caller). On threads ForSt attached, describe and clear the exception 
and return the IOError 
  status, which RocksDB already handles as a background error. This also frees 
the jthrowable local reference, which would otherwise never be released on such 
threads. Nothing changes for Java-originated calls. Includes a regression test 
in env_flink_test_suite that 
  fails without the fix.

  Since the frocksdb-based ForSt is in maintenance mode, could this go into a 
forstjni 0.1.9 for the 2.x line?
  
  *Workaround*
  
  Restart the TaskManager. Retrying transient errors in the FileSystem (e.g. 
S3A retry policy) lowers how often this happens, but any exception the 
FileSystem does not retry still triggers it.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to