{"record":{"id":"547d537c8b6c5705","repo":"apache/cassandra","slug":"unable-to-seek-to-position-d-in-s-d-bytes-in","errorCode":null,"errorMessage":"Unable to seek to position %d in %s (%d bytes) in partial mode","messagePattern":"Unable to seek to position (.+?) in (.+?) \\((.+?) bytes\\) in partial mode","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/commitlog/EncryptedFileSegmentInputStream.java","lineNumber":90,"sourceCode":"    public long bytesRemaining()\n    {\n        return expectedLength - (totalChunkOffset + buffer.position());\n    }\n\n    public void seek(long position)\n    {\n        long bufferPos = position - totalChunkOffset - segmentOffset;\n        while (buffer != null && bufferPos > buffer.capacity())\n        {\n            // rebuffer repeatedly until we have reached desired position\n            buffer.position(buffer.limit());\n\n            // increases totalChunkOffset\n            reBuffer();\n            bufferPos = position - totalChunkOffset - segmentOffset;\n        }\n        if (buffer == null || bufferPos < 0 || bufferPos > buffer.capacity())\n            throw new IllegalArgumentException(\n                    String.format(\"Unable to seek to position %d in %s (%d bytes) in partial mode\",\n                            position,\n                            getPath(),\n                            segmentOffset + expectedLength));\n        buffer.position((int) bufferPos);\n    }\n\n    public long bytesPastMark(DataPosition mark)\n    {\n        throw new UnsupportedOperationException();\n    }\n\n    public void reBuffer()\n    {\n        totalChunkOffset += buffer.position();\n        buffer = chunkProvider.nextChunk();\n    }\n}","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/commitlog/EncryptedFileSegmentInputStream.java#L72-L108","documentation":"EncryptedFileSegmentInputStream.seek(position) in partial mode computes a buffer position within the current decrypted chunk. If the resulting bufferPos is negative or exceeds the chunk capacity, the requested position is unreachable in the loaded chunk and IllegalArgumentException is thrown. This happens when replay tries to seek past the readable (decrypted/partial) region of an encrypted commit log segment.","triggerScenarios":"Seeking to an offset beyond segmentOffset + expectedLength or into a region whose chunk could not be decrypted/loaded, e.g. replaying a truncated encrypted segment or one encrypted with different key/provider settings.","commonSituations":"Commit log encrypted with transparent data encryption keys that were rotated/lost; truncated encrypted segment restored from partial backup; replaying a segment while its length metadata disagrees with actual ciphertext.","solutions":["Restore the full encrypted segment file and its encryption key / KMIP access.","Verify commit log encryption settings (transparent_data_encryption_options) match those used when the segment was written.","Accept partial replay by dropping the damaged segment and repairing data via nodetool repair.","Check that the file wasn't truncated during backup/restore (compare sizes with source)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (position > segmentOffset + expectedLength)\n    throw new IllegalArgumentException(\"Seek beyond encrypted segment length\");","typeGuard":null,"tryCatchPattern":"try {\n    reader.seek(pos);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Encrypted commitlog seek failed (truncation or key mismatch): {}\", e.getMessage());\n}","preventionTips":["Ensure encryption keys/KMIP used at write time remain available at replay","Keep transparent_data_encryption_options consistent between writer and replayer","Verify restored encrypted files were not truncated (size comparison)"],"tags":["commitlog","encryption","replay","seek"],"backgroundTag":"file-read-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}