Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into HDDS-815
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvekshayr committed Feb 7, 2024
2 parents 2d95bb5 + 60bcdaf commit 312b36c
Show file tree
Hide file tree
Showing 72 changed files with 896 additions and 1,070 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public class BlockDataStreamOutput implements ByteBufferStreamOutput {
private final DataStreamOutput out;
private CompletableFuture<DataStreamReply> dataStreamCloseReply;
private List<CompletableFuture<DataStreamReply>> futures = new ArrayList<>();
private final long syncSize = 0; // TODO: disk sync is disabled for now
private static final long SYNC_SIZE = 0; // TODO: disk sync is disabled for now
private long syncPosition = 0;
private StreamBuffer currentBuffer;
private XceiverClientMetrics metrics;
Expand Down Expand Up @@ -630,9 +630,9 @@ public boolean isClosed() {
}

private boolean needSync(long position) {
if (syncSize > 0) {
if (SYNC_SIZE > 0) {
// TODO: or position >= fileLength
if (position - syncPosition >= syncSize) {
if (position - syncPosition >= SYNC_SIZE) {
syncPosition = position;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* This test class verifies the parsing of SCM endpoint config settings. The
Expand Down Expand Up @@ -234,7 +233,7 @@ public void testVerifyResourceName() {
}

@Test
public void testVerifyKeyName() {
void testVerifyKeyName() throws IllegalArgumentException {
List<String> invalidNames = new ArrayList<>();
invalidNames.add("#");
invalidNames.add("ab^cd");
Expand Down Expand Up @@ -276,13 +275,7 @@ public void testVerifyKeyName() {
validNames.add("dollar$");

for (String name : validNames) {
try {
HddsClientUtils.verifyKeyName(name);
// not throwing up on a valid name. it's working.
} catch (IllegalArgumentException e) {
// throwing up on an valid name. it's not working.
fail("Rejected valid string [" + name + "] as a name");
}
HddsClientUtils.verifyKeyName(name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static org.apache.hadoop.ozone.ClientVersion.VERSION_HANDLES_UNKNOWN_DN_PORTS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test for {@link DatanodeDetails}.
Expand All @@ -50,14 +49,10 @@ void protoIncludesNewPortsOnlyForV1() {
}

public static void assertPorts(HddsProtos.DatanodeDetailsProto dn,
Set<Port.Name> expectedPorts) {
Set<Port.Name> expectedPorts) throws IllegalArgumentException {
assertEquals(expectedPorts.size(), dn.getPortsCount());
for (HddsProtos.Port port : dn.getPortsList()) {
try {
assertThat(expectedPorts).contains(Port.Name.valueOf(port.getName()));
} catch (IllegalArgumentException e) {
fail("Unknown port: " + port.getName());
}
assertThat(expectedPorts).contains(Port.Name.valueOf(port.getName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test {@link ChunkBuffer} implementations.
Expand All @@ -49,23 +48,23 @@ private static int nextInt(int n) {

@Test
@Timeout(1)
public void testImplWithByteBuffer() {
void testImplWithByteBuffer() throws IOException {
runTestImplWithByteBuffer(1);
runTestImplWithByteBuffer(1 << 10);
for (int i = 0; i < 10; i++) {
runTestImplWithByteBuffer(nextInt(100) + 1);
}
}

private static void runTestImplWithByteBuffer(int n) {
private static void runTestImplWithByteBuffer(int n) throws IOException {
final byte[] expected = new byte[n];
ThreadLocalRandom.current().nextBytes(expected);
runTestImpl(expected, 0, ChunkBuffer.allocate(n));
}

@Test
@Timeout(1)
public void testIncrementalChunkBuffer() {
void testIncrementalChunkBuffer() throws IOException {
runTestIncrementalChunkBuffer(1, 1);
runTestIncrementalChunkBuffer(4, 8);
runTestIncrementalChunkBuffer(16, 1 << 10);
Expand All @@ -76,7 +75,7 @@ public void testIncrementalChunkBuffer() {
}
}

private static void runTestIncrementalChunkBuffer(int increment, int n) {
private static void runTestIncrementalChunkBuffer(int increment, int n) throws IOException {
final byte[] expected = new byte[n];
ThreadLocalRandom.current().nextBytes(expected);
runTestImpl(expected, increment,
Expand All @@ -85,7 +84,7 @@ private static void runTestIncrementalChunkBuffer(int increment, int n) {

@Test
@Timeout(1)
public void testImplWithList() {
void testImplWithList() throws IOException {
runTestImplWithList(4, 8);
runTestImplWithList(16, 1 << 10);
for (int i = 0; i < 10; i++) {
Expand All @@ -95,7 +94,7 @@ public void testImplWithList() {
}
}

private static void runTestImplWithList(int count, int n) {
private static void runTestImplWithList(int count, int n) throws IOException {
final byte[] expected = new byte[n];
ThreadLocalRandom.current().nextBytes(expected);

Expand All @@ -117,7 +116,7 @@ private static void runTestImplWithList(int count, int n) {
runTestImpl(expected, -1, impl);
}

private static void runTestImpl(byte[] expected, int bpc, ChunkBuffer impl) {
private static void runTestImpl(byte[] expected, int bpc, ChunkBuffer impl) throws IOException {
final int n = expected.length;
System.out.println("n=" + n + ", impl=" + impl);

Expand Down Expand Up @@ -207,18 +206,12 @@ private static void assertToByteString(
"offset=" + offset + ", length=" + length);
}

private static void assertWrite(byte[] expected, ChunkBuffer impl) {
private static void assertWrite(byte[] expected, ChunkBuffer impl) throws IOException {
impl.rewind();
assertEquals(0, impl.position());

ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length);

try {
impl.writeTo(new MockGatheringChannel(Channels.newChannel(output)));
} catch (IOException e) {
fail("Unexpected error: " + e);
}

impl.writeTo(new MockGatheringChannel(Channels.newChannel(output)));
assertArrayEquals(expected, output.toByteArray());
assertFalse(impl.hasRemaining());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -145,7 +144,7 @@ public void testContainerCacheEviction() throws Exception {
}

@Test
public void testConcurrentDBGet() throws Exception {
void testConcurrentDBGet() throws Exception {
File root = new File(testRoot);
root.mkdirs();
root.deleteOnExit();
Expand All @@ -172,11 +171,7 @@ public void testConcurrentDBGet() throws Exception {
futureList.add(executorService.submit(task));
futureList.add(executorService.submit(task));
for (Future future: futureList) {
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
fail("Should get the DB instance");
}
future.get();
}

ReferenceCountedDB db = cache.getDB(1, "RocksDB",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class TestDatanodeStateMachine {
LoggerFactory.getLogger(TestDatanodeStateMachine.class);
// Changing it to 1, as current code checks for multiple scm directories,
// and fail if exists
private final int scmServerCount = 1;
private static final int SCM_SERVER_COUNT = 1;
private List<String> serverAddresses;
private List<RPC.Server> scmServers;
private List<ScmTestMock> mockServers;
Expand All @@ -91,7 +91,7 @@ void setUp() throws Exception {
serverAddresses = new ArrayList<>();
scmServers = new ArrayList<>();
mockServers = new ArrayList<>();
for (int x = 0; x < scmServerCount; x++) {
for (int x = 0; x < SCM_SERVER_COUNT; x++) {
int port = SCMTestUtils.getReuseableAddress().getPort();
String address = "127.0.0.1";
serverAddresses.add(address + ":" + port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test DatanodeStoreCache.
Expand All @@ -43,7 +42,7 @@ public class TestDatanodeStoreCache {
private OzoneConfiguration conf = new OzoneConfiguration();

@Test
public void testBasicOperations() throws IOException {
void testBasicOperations() throws IOException {
DatanodeStoreCache cache = DatanodeStoreCache.getInstance();
String dbPath1 = Files.createDirectory(folder.resolve("basic1"))
.toFile().toString();
Expand Down Expand Up @@ -71,11 +70,7 @@ public void testBasicOperations() throws IOException {
assertEquals(1, cache.size());

// test remove non-exist
try {
cache.removeDB(dbPath1);
} catch (Exception e) {
fail("Should not throw " + e);
}
cache.removeDB(dbPath1);

// test shutdown
cache.shutdownCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* This class tests create/read .container files.
Expand Down Expand Up @@ -205,41 +204,35 @@ public void testIncorrectContainerFile(ContainerLayoutVersion layout) {


@ContainerLayoutTestInfo.ContainerTest
public void testCheckBackWardCompatibilityOfContainerFile(
ContainerLayoutVersion layout) {
void testCheckBackWardCompatibilityOfContainerFile(
ContainerLayoutVersion layout) throws Exception {
setLayoutVersion(layout);
// This test is for if we upgrade, and then .container files added by new
// server will have new fields added to .container file, after a while we
// decided to rollback. Then older ozone can read .container files
// created or not.

try {
String containerFile = "additionalfields.container";
//Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(containerFile).getFile());
KeyValueContainerData kvData = (KeyValueContainerData) ContainerDataYaml
.readContainerFile(file);
ContainerUtils.verifyChecksum(kvData, conf);
String containerFile = "additionalfields.container";
//Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(containerFile).getFile());
KeyValueContainerData kvData = (KeyValueContainerData) ContainerDataYaml
.readContainerFile(file);
ContainerUtils.verifyChecksum(kvData, conf);

//Checking the Container file data is consistent or not
assertEquals(ContainerProtos.ContainerDataProto.State.CLOSED, kvData
.getState());
assertEquals(CONTAINER_DB_TYPE, kvData.getContainerDBType());
assertEquals(ContainerProtos.ContainerType.KeyValueContainer, kvData
.getContainerType());
assertEquals(9223372036854775807L, kvData.getContainerID());
assertEquals("/hdds/current/aed-fg4-hji-jkl/containerDir0/1", kvData
.getChunksPath());
assertEquals("/hdds/current/aed-fg4-hji-jkl/containerDir0/1", kvData
.getMetadataPath());
assertEquals(FILE_PER_CHUNK, kvData.getLayoutVersion());
assertEquals(2, kvData.getMetadata().size());

} catch (Exception ex) {
ex.printStackTrace();
fail("testCheckBackWardCompatibilityOfContainerFile failed");
}
//Checking the Container file data is consistent or not
assertEquals(ContainerProtos.ContainerDataProto.State.CLOSED, kvData
.getState());
assertEquals(CONTAINER_DB_TYPE, kvData.getContainerDBType());
assertEquals(ContainerProtos.ContainerType.KeyValueContainer, kvData
.getContainerType());
assertEquals(9223372036854775807L, kvData.getContainerID());
assertEquals("/hdds/current/aed-fg4-hji-jkl/containerDir0/1", kvData
.getChunksPath());
assertEquals("/hdds/current/aed-fg4-hji-jkl/containerDir0/1", kvData
.getMetadataPath());
assertEquals(FILE_PER_CHUNK, kvData.getLayoutVersion());
assertEquals(2, kvData.getMetadata().size());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.apache.hadoop.ozone.container.replication.CopyContainerCompression;
import org.apache.hadoop.util.DiskChecker;

import org.assertj.core.api.Fail;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -812,7 +811,7 @@ public void testKeyValueDataProtoBufMsg(ContainerTestVersionInfo versionInfo)
}

@ContainerTestVersionInfo.ContainerTest
public void testAutoCompactionSmallSstFile(
void testAutoCompactionSmallSstFile(
ContainerTestVersionInfo versionInfo) throws Exception {
init(versionInfo);
assumeTrue(isSameSchemaVersion(schemaVersion, OzoneConsts.SCHEMA_V3));
Expand Down Expand Up @@ -903,8 +902,6 @@ public void testAutoCompactionSmallSstFile(
List<LiveFileMetaData> fileMetaDataList2 =
((RDBStore)(dnStore.getStore())).getDb().getLiveFilesMetaData();
assertThat(fileMetaDataList2.size()).isLessThan(fileMetaDataList1.size());
} catch (Exception e) {
Fail.fail("TestAutoCompactionSmallSstFile failed");
} finally {
// clean up
for (KeyValueContainer c : containerList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Tests the Default CA Server.
Expand Down Expand Up @@ -449,7 +448,7 @@ public void testInitWithCertChain(@TempDir Path tempDir) throws Exception {
}

@Test
public void testIntermediaryCA() throws Exception {
void testIntermediaryCA() throws Exception {

conf.set(HddsConfigKeys.HDDS_X509_MAX_DURATION, "P3650D");
securityConfig = new SecurityConfig(conf);
Expand Down Expand Up @@ -519,11 +518,8 @@ clusterId, scmId, caStore, new DefaultProfile(),
clusterId, scmId, caStore, new DefaultProfile(),
scmCertificateClient.getComponentName());

try {
scmCA.init(securityConfig, CAType.SUBORDINATE);
} catch (Exception e) {
fail("testIntermediaryCA failed during init");
}

scmCA.init(securityConfig, CAType.SUBORDINATE);
}
}

Expand Down
Loading

0 comments on commit 312b36c

Please sign in to comment.