diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java index 5a42b3a86..59933b511 100644 --- a/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java +++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java @@ -354,48 +354,48 @@ public class SeaweedOutputStream extends OutputStream { LOG.warn("[DEBUG-2024] Looking up: parentDir={} fileName={}", parentDir, fileName); - int maxRetries = 5; - long retryDelayMs = 10; // Start with 10ms - - for (int attempt = 0; attempt < maxRetries; attempt++) { - try { - LOG.warn("[DEBUG-2024] Attempt {} to lookup metadata", attempt + 1); - // Lookup the entry to verify metadata is visible - FilerProto.Entry lookedUpEntry = filerClient.lookupEntry(parentDir, fileName); - LOG.warn("[DEBUG-2024] Lookup returned: {}", (lookedUpEntry != null ? "entry found" : "null")); - - if (lookedUpEntry != null) { - long lookedUpSize = lookedUpEntry.getAttributes().getFileSize(); - - if (lookedUpSize == position) { - // Metadata is correct and visible - if (attempt > 0) { - LOG.info("[DEBUG-2024] Metadata visible after {} retries: path={} size={}", - attempt, path, position); + int maxRetries = 5; + long retryDelayMs = 10; // Start with 10ms + + for (int attempt = 0; attempt < maxRetries; attempt++) { + try { + LOG.warn("[DEBUG-2024] Attempt {} to lookup metadata", attempt + 1); + // Lookup the entry to verify metadata is visible + FilerProto.Entry lookedUpEntry = filerClient.lookupEntry(parentDir, fileName); + LOG.warn("[DEBUG-2024] Lookup returned: {}", (lookedUpEntry != null ? "entry found" : "null")); + + if (lookedUpEntry != null) { + long lookedUpSize = lookedUpEntry.getAttributes().getFileSize(); + + if (lookedUpSize == position) { + // Metadata is correct and visible + if (attempt > 0) { + LOG.info("[DEBUG-2024] Metadata visible after {} retries: path={} size={}", + attempt, path, position); + } + return; + } else { + // Metadata is stale + LOG.warn("[DEBUG-2024] Metadata stale on attempt {}: path={} expected={} actual={}", + attempt + 1, path, position, lookedUpSize); } - return; - } else { - // Metadata is stale - LOG.warn("[DEBUG-2024] Metadata stale on attempt {}: path={} expected={} actual={}", - attempt + 1, path, position, lookedUpSize); } - } - // Metadata not yet visible or stale, retry - if (attempt < maxRetries - 1) { - Thread.sleep(retryDelayMs); - retryDelayMs *= 2; // Exponential backoff - } + // Metadata not yet visible or stale, retry + if (attempt < maxRetries - 1) { + Thread.sleep(retryDelayMs); + retryDelayMs *= 2; // Exponential backoff + } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new IOException("Interrupted while waiting for metadata visibility", e); - } catch (Exception e) { - LOG.warn("[DEBUG-2024] Error checking metadata visibility on attempt {}: {}", - attempt + 1, e.getMessage()); - // Continue to next retry + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IOException("Interrupted while waiting for metadata visibility", e); + } catch (Exception e) { + LOG.warn("[DEBUG-2024] Error checking metadata visibility on attempt {}: {}", + attempt + 1, e.getMessage()); + // Continue to next retry + } } - } // If we get here, metadata may still not be visible, but we've done our best LOG.warn("[DEBUG-2024] Metadata may not be immediately visible after {} retries: path={} size={}", diff --git a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java index 3c9815d36..26d93873c 100644 --- a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java +++ b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java @@ -161,13 +161,40 @@ public class SeaweedFileSystemStore { if (source.isRoot()) { return; } - LOG.info("rename source: {} destination:{}", source, destination); + LOG.warn("[DEBUG-2024] RENAME START: {} => {}", source, destination); FilerProto.Entry entry = lookupEntry(source); if (entry == null) { LOG.warn("rename non-existing source: {}", source); return; } + + // Log source file metadata before rename + long sourceSize = entry.getAttributes().getFileSize(); + int sourceChunks = entry.getChunksCount(); + LOG.warn("[DEBUG-2024] Source file metadata: size={} chunks={}", sourceSize, sourceChunks); + filerClient.mv(source.toUri().getPath(), destination.toUri().getPath()); + + LOG.warn("[DEBUG-2024] RENAME COMPLETE: {} => {}", source, destination); + + // Lookup destination to verify metadata was preserved + FilerProto.Entry destEntry = lookupEntry(destination); + if (destEntry != null) { + long destSize = destEntry.getAttributes().getFileSize(); + int destChunks = destEntry.getChunksCount(); + LOG.warn("[DEBUG-2024] Destination file metadata: size={} chunks={}", destSize, destChunks); + + if (sourceSize != destSize) { + LOG.error("[DEBUG-2024] METADATA MISMATCH! Source size={} but destination size={}", + sourceSize, destSize); + } + if (sourceChunks != destChunks) { + LOG.error("[DEBUG-2024] CHUNK COUNT MISMATCH! Source chunks={} but destination chunks={}", + sourceChunks, destChunks); + } + } else { + LOG.error("[DEBUG-2024] Destination file not found after rename!"); + } } public OutputStream createFile(final Path path,