Skip to content

Conversation

@devabhishekpal
Copy link

What changes were proposed in this pull request?

We are changing the visibility of LogSegmentStartEnd#getStartIndex() and LogSegmentStartEnd#getEndIndex() to public.
This will allow external tools that deal with the RATIS log, to directly make changes to it.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/RATIS-2281

How was this patch tested?

Patch was tested using unit tests

@devabhishekpal
Copy link
Author

@errose28 I am not too sure of the use case, do you think this change suffices?

Or did the ticket mean to add new methods to LogSegmentPath class which expose the getStartIndex and getEndIndex.
as in:

class LogSegmentPath {
    ....
    
    public long getStartIndex() {
        return this.startEnd.getStartIndex()
     }

     public long getEndIndex() {
         return this.startEnd.getEndIndex()
     }
}

@devabhishekpal devabhishekpal marked this pull request as ready for review November 22, 2025 11:52
@adoroszlai adoroszlai requested a review from szetszwo November 25, 2025 16:56
@szetszwo
Copy link
Contributor

@devabhishekpal , let's make sure how the methods are going to be used before changing them.

Copy link
Contributor

@errose28 errose28 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment on the Jira and linked it to the Ozone task for context. We will need a follow-up task in Ozone to migrate our debug tool to use this new API when our Ratis version is updated.

@devabhishekpal
Copy link
Author

@szetszwo could you take a look as well?

@szetszwo
Copy link
Contributor

szetszwo commented Dec 9, 2025

@devabhishekpal , @errose28 ,

I think about this change. It seems not a good idea to simple changing the methods to public and let other projects using it. We should have some kind of APIs.

I wonder if the we could move the RaftLog tool from Ozone to Ratis?

As a workaround, Ozone could add a RaftLogUtils class in the org.apache.ratis.server.raftlog.segmented package for accessing the package private methods in the meantime. (Something similar to https://github.com/apache/ozone/blob/master/hadoop-hdds/common/src/main/java/com/google/protobuf/ProtoUtils.java )

@devabhishekpal
Copy link
Author

Hmm, seems like a good long term plan. Maybe other projects dependent on RATIS can also use such tools.
@errose28 what do you think of the effort on this shift of RaftLog tools from Ozone to Ratis?

@devabhishekpal
Copy link
Author

@szetszwo by ratis log tool you are referring to the OM Ratis log repair tool?

@errose28
Copy link
Contributor

I think about this change. It seems not a good idea to simple changing the methods to public and let other projects using it. We should have some kind of APIs.

The class is already public so it is part of the API. We are not changing arbitrary methods to public either. The class is named LogSegmentStartEnd, so it seems reasonable for it to expose read-only methods to retrieve the start and end indices that it is named for. The compareTo method which works on these indices is public as well.

I wonder if the we could move the RaftLog tool from Ozone to Ratis?

This might be possible but the implementation may look strange. The tool is to replace the message contents of one raft log entry with a different type of message/content which is specific to Ozone. An implementation in Ratis that takes a byte string to replace the log entry with could be used for this. However I don't see how adding a low level mutator to the public API is less harmful than two read-only methods in an already public class.

As a workaround, Ozone could add a RaftLogUtils class in the org.apache.ratis.server.raftlog.segmented package for accessing the package private methods in the meantime.

I'd rather not do a hack like this if we have the above two options available.

@szetszwo
Copy link
Contributor

szetszwo commented Dec 17, 2025

The class is already public so it is part of the API. ...

For servers, only the classes in ratis-server-api are public APIs. Public classes in ratis-server are not.

... The tool is to replace the message contents of one raft log entry with a different type of message/content which is specific to Ozone. An implementation in Ratis that takes a byte string to replace the log entry with could be used for this.

If the tool is in Ratis, it could let the applications such as Ozone pass a function for doing the replacement.

Note that if the tool is in Ratis, it can access the private API in its implementation.

... I don't see how adding a low level mutator to the public API is less harmful than two read-only methods in an already public class.

It is easier to define a public tool API than a public server API. In this case, if LogSegmentStartEnd is a public server API, it means that we have to support such segment files forever. Then, it limits the flexibility of the underlying implementation (e.g. RATIS-2370 SegmentedRaftLog v2).

@errose28
Copy link
Contributor

If the tool is in Ratis, it could let the applications such as Ozone pass a function for doing the replacement.

I agree this would probably be the best thing long term. We can file a Jira for this and migrate Ozone when it is ready. In the mean time I think we can keep using the regex workaround to identify log segments rather than the private package approach. Should we close this PR?

@szetszwo
Copy link
Contributor

Sure, let's close this. Thanks for your understanding.

@devabhishekpal
Copy link
Author

Thanks for the inputs @errose28 @szetszwo . Closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants