[crac] RFR: Handle open file descriptors with configurable policies [v3]

Anton Kozlov akozlov at openjdk.org
Thu Jun 8 18:29:06 UTC 2023

On Fri, 12 May 2023 13:29:08 GMT, Radim Vansa <duke at openjdk.org> wrote:

>> When the application does not close some file descriptors through Resources we can use `jdk.crac.fd-policy.checkpoint` and `jdk.crac.fd-policy.restore` to configure the behaviour.
>> These properties can specify a list of File.pathSeparator-separated key=value pairs, where the key can be one of:
>> * numeric file descriptor
>> * path using 'glob' pattern matching (see FileSystem.getPathMatcher() for details)
>> * keywords FIFO and SOCKET that match pipes and sockets
>> The value should match one of possible values from OpenFDPolicies.BeforeCheckpoint and OpenFDPolicies.AfterRestore
> Radim Vansa has updated the pull request incrementally with one additional commit since the last revision:
>   Effectively revert previous commit: Initialize logger in <clinit>

src/java.base/share/classes/java/io/FileDescriptor.java line 67:

> 65:         private String originalPath;
> 66:         private int originalFlags;
> 67:         private long originalOffset;

Regarding the design, path and offset are features of a file desriptor referring to the filesystem, but they do not make sense to socket FD.

src/java.base/share/classes/java/io/FileDescriptor.java line 456:

> 454:             // this is used probably as the file moved on the filesystem but the contents
> 455:             // are the same.
> 456:             if (!reopen(resource.originalFd, path, resource.originalFlags, resource.originalOffset)) {

Another option is a log file in the append mode, which may grow larger -- in that case we'd like to have that in append mode with position at the end. Probably that is handled by setting proper flags, but at least this would contradict with the comment.

src/java.base/share/classes/jdk/crac/impl/OpenFDPolicies.java line 23:

> 21: public class OpenFDPolicies<P> {
> 22:     public static final String CHECKPOINT_PROPERTY = "jdk.crac.fd-policy.checkpoint";
> 23:     public static final String RESTORE_PROPERTY = "jdk.crac.fd-policy.restore";

Having separated policies for checkpoint and restore enables some weird configuration, when e.g. checkpoint specifing CLOSE and restore -- REOPEN. It would be better to have a combined, consisted checkpoint-restore policy that specifes both parts at once.

src/java.base/share/classes/jdk/crac/impl/OpenFDPolicies.java line 228:

> 226:             return fifoPolicy;
> 227:         } else if (type.equals("socket")) {
> 228:             return socketPolicy;

Obviously, only a single policy is possible for all sockets. In general sockets are much harder than files, and in not so many cases we can automatically handle them. I think some connection-less sockets _may_ be covered, and some listening sockets.

If we continue this implementation, FileDescriptor (a rather simple object intially) will grow larger and larger, knowing about all possible uses in the JDK.


PR Review Comment: https://git.openjdk.org/crac/pull/69#discussion_r1223386909
PR Review Comment: https://git.openjdk.org/crac/pull/69#discussion_r1223382818
PR Review Comment: https://git.openjdk.org/crac/pull/69#discussion_r1223394991
PR Review Comment: https://git.openjdk.org/crac/pull/69#discussion_r1223400286

More information about the crac-dev mailing list