Skip to content

Commit a4fc716

Browse files
author
lijinglun
committed
HADOOP-19236. Incorporate VolcanoEngine Cloud TOS File System Implementation.
1 parent 0698e8a commit a4fc716

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+9602
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.tosfs;
20+
21+
import org.apache.hadoop.fs.tosfs.util.ParseUtils;
22+
23+
public class TestEnv {
24+
public static final String ENV_TOS_UNIT_TEST_ENABLED = "TOS_UNIT_TEST_ENABLED";
25+
private static final boolean TOS_TEST_ENABLED;
26+
27+
static {
28+
TOS_TEST_ENABLED = ParseUtils.envAsBoolean(ENV_TOS_UNIT_TEST_ENABLED, false);
29+
}
30+
31+
public static boolean checkTestEnabled() {
32+
return TOS_TEST_ENABLED;
33+
}
34+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.tosfs;
20+
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
24+
public class TestRawFSUtils {
25+
26+
@Test
27+
public void testIsAncestor() {
28+
Assert.assertTrue(RawFSUtils.inSubtree("/", "/"));
29+
Assert.assertTrue(RawFSUtils.inSubtree("/", "/a"));
30+
Assert.assertTrue(RawFSUtils.inSubtree("/a", "/a"));
31+
Assert.assertFalse(RawFSUtils.inSubtree("/a", "/"));
32+
Assert.assertTrue(RawFSUtils.inSubtree("/", "/a/b/c"));
33+
Assert.assertFalse(RawFSUtils.inSubtree("/a/b/c", "/"));
34+
Assert.assertTrue(RawFSUtils.inSubtree("/", "/a/b/c.txt"));
35+
Assert.assertFalse(RawFSUtils.inSubtree("/a/b/c.txt", "/"));
36+
Assert.assertTrue(RawFSUtils.inSubtree("/a/b/", "/a/b"));
37+
Assert.assertTrue(RawFSUtils.inSubtree("/a/b/", "/a/b/c"));
38+
Assert.assertFalse(RawFSUtils.inSubtree("/a/b/c", "/a/b"));
39+
}
40+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.tosfs;
20+
21+
import org.apache.hadoop.conf.Configuration;
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
25+
import java.io.FileNotFoundException;
26+
import java.io.IOException;
27+
import java.net.URI;
28+
import java.net.URISyntaxException;
29+
30+
import static org.junit.Assert.assertThrows;
31+
32+
public class TestRawFileSystem {
33+
@Test
34+
public void testInitializeFileSystem() throws URISyntaxException, IOException {
35+
Configuration conf = new Configuration();
36+
try (RawFileSystem fs = new RawFileSystem()) {
37+
fs.initialize(new URI("filestore://bucket_a/a/b/c"), conf);
38+
Assert.assertEquals("bucket_a", fs.bucket());
39+
40+
fs.initialize(new URI("filestore://bucket-/a/b/c"), conf);
41+
Assert.assertEquals("bucket-", fs.bucket());
42+
43+
fs.initialize(new URI("filestore://-bucket/a/b/c"), conf);
44+
Assert.assertEquals("-bucket", fs.bucket());
45+
}
46+
}
47+
48+
@Test
49+
public void testBucketNotExist() {
50+
Configuration conf = new Configuration();
51+
RawFileSystem fs = new RawFileSystem();
52+
assertThrows("Bucket doesn't exist.", FileNotFoundException.class,
53+
() -> fs.initialize(new URI("tos://not-exist-bucket/"), conf));
54+
}
55+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.tosfs;
20+
21+
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.hadoop.fs.FileChecksum;
23+
import org.apache.hadoop.fs.Path;
24+
import org.apache.hadoop.fs.tosfs.conf.ConfKeys;
25+
import org.apache.hadoop.fs.tosfs.conf.FileStoreKeys;
26+
import org.apache.hadoop.fs.tosfs.conf.TosKeys;
27+
import org.apache.hadoop.fs.tosfs.object.ChecksumType;
28+
import org.apache.hadoop.fs.tosfs.object.ObjectStorage;
29+
import org.apache.hadoop.fs.tosfs.object.ObjectStorageFactory;
30+
import org.apache.hadoop.fs.tosfs.util.TempFiles;
31+
import org.apache.hadoop.fs.tosfs.util.TestUtility;
32+
import org.apache.hadoop.fs.tosfs.util.UUIDUtils;
33+
import org.junit.After;
34+
import org.junit.Assume;
35+
import org.junit.Test;
36+
import org.junit.runner.RunWith;
37+
import org.junit.runners.Parameterized;
38+
39+
import java.net.URI;
40+
import java.net.URISyntaxException;
41+
import java.util.ArrayList;
42+
import java.util.List;
43+
44+
import static org.apache.hadoop.fs.tosfs.object.tos.TOS.TOS_SCHEME;
45+
import static org.junit.Assert.assertArrayEquals;
46+
import static org.junit.Assert.assertEquals;
47+
48+
@RunWith(Parameterized.class)
49+
public class TestTosChecksum {
50+
private static final String FILE_STORE_ROOT = TempFiles.newTempDir("TestTosChecksum");
51+
private static final String ALGORITHM_NAME = "mock-algorithm";
52+
private static final String PREFIX = UUIDUtils.random();
53+
54+
@Parameterized.Parameters(name = "checksumType = {0}, conf = {1}, uri = {2}, objectStorage = {3}")
55+
public static Iterable<Object[]> createStorage() throws URISyntaxException {
56+
Assume.assumeTrue(TestEnv.checkTestEnabled());
57+
return createTestObjectStorage(FILE_STORE_ROOT);
58+
}
59+
60+
public static Iterable<Object[]> createTestObjectStorage(String fileStoreRoot)
61+
throws URISyntaxException {
62+
List<Object[]> list = new ArrayList<>();
63+
64+
// The 1st argument.
65+
Configuration fileStoreConf = new Configuration();
66+
fileStoreConf.set(FileStoreKeys.FS_FILESTORE_CHECKSUM_ALGORITHM, ALGORITHM_NAME);
67+
fileStoreConf.set(FileStoreKeys.FS_FILESTORE_CHECKSUM_TYPE, ChecksumType.MD5.name());
68+
fileStoreConf.set(ConfKeys.FS_OBJECT_STORAGE_ENDPOINT.key("filestore"), fileStoreRoot);
69+
70+
URI uri0 = new URI("filestore://" + TestUtility.bucket() + "/");
71+
Object[] objs = new Object[] { ChecksumType.MD5, fileStoreConf, uri0,
72+
ObjectStorageFactory.create(uri0.getScheme(), uri0.getAuthority(), fileStoreConf) };
73+
list.add(objs);
74+
75+
// The 2nd argument.
76+
Configuration tosConf = new Configuration();
77+
tosConf.set(TosKeys.FS_TOS_CHECKSUM_ALGORITHM, ALGORITHM_NAME);
78+
tosConf.set(TosKeys.FS_TOS_CHECKSUM_TYPE, ChecksumType.CRC32C.name());
79+
80+
URI uri1 = new URI(TOS_SCHEME + "://" + TestUtility.bucket() + "/");
81+
objs = new Object[] { ChecksumType.CRC32C, tosConf, uri1,
82+
ObjectStorageFactory.create(uri1.getScheme(), uri1.getAuthority(), tosConf) };
83+
list.add(objs);
84+
85+
return list;
86+
}
87+
88+
@After
89+
public void tearDown() {
90+
objectStorage.deleteAll(PREFIX);
91+
}
92+
93+
private ChecksumType type;
94+
private Configuration conf;
95+
private URI uri;
96+
private ObjectStorage objectStorage;
97+
98+
public TestTosChecksum(ChecksumType type, Configuration conf, URI uri,
99+
ObjectStorage objectStorage) {
100+
this.type = type;
101+
this.conf = conf;
102+
this.uri = uri;
103+
this.objectStorage = objectStorage;
104+
}
105+
106+
@Test
107+
public void testChecksumInfo() {
108+
assertEquals(ALGORITHM_NAME, objectStorage.checksumInfo().algorithm());
109+
assertEquals(type, objectStorage.checksumInfo().checksumType());
110+
}
111+
112+
@Test
113+
public void testFileChecksum() throws Exception {
114+
try (RawFileSystem fs = new RawFileSystem()) {
115+
fs.initialize(uri, conf);
116+
Path file = new Path("/" + PREFIX, "testFileChecksum");
117+
fs.create(file).close();
118+
FileChecksum checksum = fs.getFileChecksum(file, Long.MAX_VALUE);
119+
assertEquals(ALGORITHM_NAME, checksum.getAlgorithmName());
120+
121+
String key = file.toString().substring(1);
122+
byte[] checksumData = objectStorage.head(key).checksum();
123+
assertArrayEquals(checksumData, checksum.getBytes());
124+
}
125+
}
126+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.tosfs;
20+
21+
import org.apache.hadoop.conf.Configuration;
22+
import org.apache.hadoop.fs.CommonConfigurationKeys;
23+
import org.apache.hadoop.fs.tosfs.util.TestUtility;
24+
import org.junit.Assume;
25+
import org.junit.BeforeClass;
26+
import org.junit.Test;
27+
28+
import java.io.IOException;
29+
import java.net.URI;
30+
import java.net.URISyntaxException;
31+
32+
import static org.junit.Assert.assertThrows;
33+
34+
public class TestTosFileSystem {
35+
36+
@BeforeClass
37+
public static void before() {
38+
Assume.assumeTrue(TestEnv.checkTestEnabled());
39+
}
40+
41+
@Test
42+
public void testUriVerification() throws URISyntaxException, IOException {
43+
Configuration conf = new Configuration(false);
44+
conf.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY, "hdfs://cluster-0/");
45+
46+
TosFileSystem tfs = new TosFileSystem();
47+
assertThrows("Expect invalid uri error.", IllegalArgumentException.class,
48+
() -> tfs.initialize(new URI("hdfs://cluster/"), conf));
49+
assertThrows("Expect invalid uri error.", IllegalArgumentException.class,
50+
() -> tfs.initialize(new URI("/path"), conf));
51+
tfs.initialize(new URI(String.format("tos://%s/", TestUtility.bucket())), conf);
52+
}
53+
}

0 commit comments

Comments
 (0)