chore(clean up): remove unused imports, unnecessary object impls, concurrency/coroutine issues, trailing commas, etc.

This commit is contained in:
2026-05-24 22:56:19 +04:00
parent 71aac8afc9
commit ac05ad8733
16 changed files with 85 additions and 83 deletions
@@ -7,6 +7,7 @@ import com.correx.core.artifacts.kind.FileWrittenPayload
import com.correx.infrastructure.artifactscas.segment.SegmentLayout
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.file.Files
import java.nio.file.Path
@@ -15,7 +16,7 @@ import java.nio.file.attribute.PosixFilePermissions
class DefaultMaterializingArtifactWriter : MaterializingArtifactWriter {
private companion object {
val log = LoggerFactory.getLogger(DefaultMaterializingArtifactWriter::class.java)
val log: Logger = LoggerFactory.getLogger(DefaultMaterializingArtifactWriter::class.java)
const val DEFAULT_MODE = "644"
const val OCTAL_RADIX = 8
const val POSIX_PERMISSION_BITS = 9
@@ -37,21 +37,23 @@ class TailScanner(
private suspend fun scanAndRecover(activeId: Long, path: Path, startOffset: Long): TailScanReport {
var recovered = 0
var truncatedAt: Long? = null
RandomAccessFile(path.toFile(), "rw").use { raf ->
val fileLen = raf.length()
var pos = startOffset
while (pos < fileLen) {
val step = tryReadRecord(raf, pos, fileLen)
if (step == null) {
truncatedAt = pos
break
withContext(Dispatchers.IO) {
RandomAccessFile(path.toFile(), "rw").use { raf ->
val fileLen = raf.length()
var pos = startOffset
while (pos < fileLen) {
val step = tryReadRecord(raf, pos, fileLen)
if (step == null) {
truncatedAt = pos
break
}
index.insert(step.hash, Location(activeId, pos, step.length))
recovered += 1
pos += SegmentLayout.HEADER_SIZE + step.length
}
index.insert(step.hash, Location(activeId, pos, step.length))
recovered += 1
pos += SegmentLayout.HEADER_SIZE + step.length
// Truncate at first bad/partial record so writer resumes at a clean boundary.
truncatedAt?.let { raf.setLength(it) }
}
// Truncate at first bad/partial record so writer resumes at a clean boundary.
truncatedAt?.let { raf.setLength(it) }
}
return TailScanReport(activeId, startOffset, recovered, truncatedAt)
}