When implementing the LSM-Tree model, I encountered that when I try to write from MemTable to SSTable and then write to the file, an AccessDeniedException occurs. The code below is shown. The base folder on the fifth line is passed as a parameter to MemTable and points to the TempDir directory (@TempDir File data)

public static final String SUFFIX = ".dat"; public static final String TEMP = ".tmp"; if (tableSize >= MAX_HEAP / 3) { final File tmp = new File(base, generation + TEMP); ssTable.upsert(this.iterator(ByteBuffer.allocate(0)), tmp); final File dest = new File(base, generation + SUFFIX); Files.move(tmp.toPath(), dest.toPath(), StandardCopyOption.ATOMIC_MOVE); generation++; storage = null; storage = new ConcurrentSkipListMap<>(); tableSize = 0; } 

and already in SSTable, here is such a record model

 public void upsert(Iterator <Cluster> clusters, File file) throws IOException { try(FileChannel fileChannel = FileChannel.open( file.toPath(), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) { final List<Long> offsets = new ArrayList<>(); long offset = 0; while (clusters.hasNext()) { offsets.add(offset); final Cluster cluster = clusters.next(); // Key final ByteBuffer key = cluster.getKey(); final int keySize = cluster.getKey().remaining(); fileChannel.write(BytesWrapper.fromInt(keySize)); offset += Integer.BYTES; fileChannel.write(key); offset += keySize; // Value final ClusterValue value = cluster.getClusterValue(); // Timestamp if (value.isTombstone()) { fileChannel.write(BytesWrapper.fromLong(-cluster.getClusterValue().getTimestamp())); } else { fileChannel.write(BytesWrapper.fromLong(cluster.getClusterValue().getTimestamp())); } offset += Long.BYTES; // Value if (!value.isTombstone()) { final ByteBuffer valueData = value.getData(); final int valueSize = value.getData().remaining(); fileChannel.write(BytesWrapper.fromInt(valueSize)); offset += Integer.BYTES; fileChannel.write(valueData); offset += valueSize; } } // Offsets for (final Long anOffset : offsets) { fileChannel.write(BytesWrapper.fromLong(anOffset)); } //Cells fileChannel.write(BytesWrapper.fromLong(offsets.size())); } } 

Which is very strange, since the corresponding permissions for the folder are present enter image description here

    0