chia7712 commented on code in PR #21636:
URL: https://github.com/apache/kafka/pull/21636#discussion_r2890106641
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/AbstractSegments.java:
##########
@@ -120,24 +120,20 @@ public S getOrCreateSegmentIfLive(final long segmentId,
@Override
public void openExisting(final StateStoreContext context, final long
streamTime) {
- try {
- final File dir = new File(context.stateDir(), name);
- if (dir.exists()) {
- final String[] list = dir.list();
- if (list != null) {
- Arrays.stream(list)
- .map(segment -> segmentIdFromSegmentName(segment,
dir))
- .sorted() // open segments in the id order
- .filter(segmentId -> segmentId >= 0)
- .forEach(segmentId ->
getOrCreateSegment(segmentId, context));
- }
- } else {
- if (!dir.mkdir()) {
- throw new ProcessorStateException(String.format("dir %s
doesn't exist and cannot be created for segments %s", dir, name));
- }
+ final File dir = new File(context.stateDir(), name);
+ if (dir.exists()) {
+ final String[] list = dir.list();
+ if (list != null) {
+ Arrays.stream(list)
+ .map(segment -> segmentIdFromSegmentName(segment, dir))
+ .sorted() // open segments in the id order
+ .filter(segmentId -> segmentId >= 0)
Review Comment:
Nit: it would be better to apply `filter` before `sort`
##########
streams/src/main/java/org/apache/kafka/streams/state/internals/AbstractSegments.java:
##########
@@ -120,24 +120,20 @@ public S getOrCreateSegmentIfLive(final long segmentId,
@Override
public void openExisting(final StateStoreContext context, final long
streamTime) {
- try {
- final File dir = new File(context.stateDir(), name);
- if (dir.exists()) {
- final String[] list = dir.list();
- if (list != null) {
- Arrays.stream(list)
- .map(segment -> segmentIdFromSegmentName(segment,
dir))
- .sorted() // open segments in the id order
- .filter(segmentId -> segmentId >= 0)
- .forEach(segmentId ->
getOrCreateSegment(segmentId, context));
- }
- } else {
- if (!dir.mkdir()) {
- throw new ProcessorStateException(String.format("dir %s
doesn't exist and cannot be created for segments %s", dir, name));
- }
+ final File dir = new File(context.stateDir(), name);
+ if (dir.exists()) {
Review Comment:
should we ensure the `dir` is a directory rather than regular file?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]