Skip to content

Commit

Permalink
IGNITE-13823 WAL iterator WRITE permission requirement removed. - Fixes
Browse files Browse the repository at this point in the history
#8549.

Signed-off-by: Sergey Chugunov <sergey.chugunov@gmail.com>
  • Loading branch information
ibessonov authored and sergey-chugunov-1985 committed Dec 10, 2020
1 parent afc73ec commit fb5032e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected AbstractReadFileHandle initReadHandle(
SegmentIO fileIO = null;

try {
fileIO = desc.toIO(ioFactory);
fileIO = desc.toReadOnlyIO(ioFactory);

SegmentHeader segmentHeader;

Expand Down Expand Up @@ -513,6 +513,6 @@ protected interface AbstractFileDescriptor {
* @return One of implementation of {@link FileIO}.
* @throws IOException if creation of fileIo was not success.
*/
SegmentIO toIO(FileIOFactory fileIOFactory) throws IOException;
SegmentIO toReadOnlyIO(FileIOFactory fileIOFactory) throws IOException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.jetbrains.annotations.Nullable;

import static java.nio.file.StandardOpenOption.READ;

/**
* WAL file descriptor.
*/
Expand Down Expand Up @@ -144,8 +146,8 @@ public String getAbsolutePath() {
}

/** {@inheritDoc} */
@Override public SegmentIO toIO(FileIOFactory fileIOFactory) throws IOException {
FileIO fileIO = isCompressed() ? new UnzipFileIO(file()) : fileIOFactory.create(file());
@Override public SegmentIO toReadOnlyIO(FileIOFactory fileIOFactory) throws IOException {
FileIO fileIO = isCompressed() ? new UnzipFileIO(file()) : fileIOFactory.create(file(), READ);

return new SegmentIO(idx, fileIO);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ private long lastArchivedIndex() {
@Nullable private FileDescriptor readFileDescriptor(File file, FileIOFactory ioFactory) {
FileDescriptor ds = new FileDescriptor(file);

try (SegmentIO fileIO = ds.toIO(ioFactory)) {
try (SegmentIO fileIO = ds.toReadOnlyIO(ioFactory)) {
// File may be empty when LOG_ONLY mode is enabled and mmap is disabled.
if (fileIO.size() == 0)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public LockedSegmentFileInputFactory(
id -> {
FileDescriptor segment = segmentRouter.findSegment(id);

return segment.toIO(fileIOFactory);
return segment.toReadOnlyIO(fileIOFactory);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private FileDescriptor readFileDescriptor(File file, FileIOFactory ioFactory) {
FileDescriptor ds = new FileDescriptor(file);

try (
SegmentIO fileIO = ds.toIO(ioFactory);
SegmentIO fileIO = ds.toReadOnlyIO(ioFactory);
ByteBufferExpander buf = new ByteBufferExpander(HEADER_RECORD_SIZE, ByteOrder.nativeOrder())
) {
final DataInput in = segmentFileInputFactory.createFileInput(fileIO, buf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private boolean checkBounds(long idx) {
SegmentHeader segmentHeader;
while (true) {
try {
fileIO = fd.toIO(ioFactory);
fileIO = fd.toReadOnlyIO(ioFactory);

segmentHeader = readSegmentHeader(fileIO, FILE_INPUT_FACTORY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.OpenOption;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -261,6 +264,8 @@ private String getArchiveWalDirPath(Ignite ignite) throws IgniteCheckedException
private static class CountedFileIOFactory extends RandomAccessFileIOFactory {
/** {@inheritDoc} */
@Override public FileIO create(File file, OpenOption... modes) throws IOException {
assertEquals(Collections.singletonList(StandardOpenOption.READ), Arrays.asList(modes));

return new CountedFileIO(file, modes);
}
}
Expand Down

0 comments on commit fb5032e

Please sign in to comment.