-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug][coordinator/kv] delete remote kv dir for table on coordinator server #297
base: main
Are you sure you want to change the base?
Changes from 2 commits
19b7c59
31cba62
010a7bb
a5e8ebd
f9fcf86
a7e6757
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,9 +180,11 @@ protected void startServices() throws Exception { | |
// up. | ||
// in HA for coordinator server, the processor also need to know the leader node during | ||
// start up | ||
RemoteStorageHandler remoteStorageHandler = new RemoteStorageHandler(conf); | ||
this.coordinatorEventProcessor = | ||
new CoordinatorEventProcessor( | ||
zkClient, | ||
remoteStorageHandler, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: not to define local variable, just pass |
||
metadataCache, | ||
coordinatorChannelManager, | ||
bucketSnapshotManager, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||
/* | ||||||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||||||
* | ||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
* you may not use this file except in compliance with the License. | ||||||
* You may obtain a copy of the License at | ||||||
* | ||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||
* | ||||||
* Unless required by applicable law or agreed to in writing, software | ||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
* See the License for the specific language governing permissions and | ||||||
* limitations under the License. | ||||||
*/ | ||||||
|
||||||
package com.alibaba.fluss.server.coordinator; | ||||||
|
||||||
import com.alibaba.fluss.config.Configuration; | ||||||
import com.alibaba.fluss.fs.FileSystem; | ||||||
import com.alibaba.fluss.fs.FsPath; | ||||||
import com.alibaba.fluss.metadata.TablePath; | ||||||
import com.alibaba.fluss.utils.FlussPaths; | ||||||
|
||||||
import org.slf4j.Logger; | ||||||
import org.slf4j.LoggerFactory; | ||||||
|
||||||
import java.io.IOException; | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comments for this class.. |
||||||
public class RemoteStorageHandler { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename it to |
||||||
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(RemoteStorageHandler.class); | ||||||
|
||||||
private final FsPath remoteKvDir; | ||||||
private final FileSystem remoteFileSystem; | ||||||
|
||||||
public RemoteStorageHandler(Configuration configuration) throws IOException { | ||||||
this.remoteKvDir = FlussPaths.remoteKvDir(configuration); | ||||||
this.remoteFileSystem = remoteKvDir.getFileSystem(); | ||||||
} | ||||||
|
||||||
public void createTableKvDir(TablePath tablePath, long tableId) throws IOException { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not introudce this method since it's only for testing... introduce code used only in testing will make it hard to maintain. |
||||||
remoteFileSystem.mkdirs(tableKvDir(tablePath, tableId)); | ||||||
} | ||||||
|
||||||
public void deleteTable(TablePath tablePath, long tableId) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
deleteDir(tableKvDir(tablePath, tableId)); | ||||||
// todo delete log segments file dirs of table. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't delete log segments file dirs in this pr? |
||||||
} | ||||||
|
||||||
public boolean isTableKvDirExists(TablePath tablePath, long tableId) throws IOException { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dito: do not introudce this method since it's only for testing |
||||||
return isDirExists(tableKvDir(tablePath, tableId)); | ||||||
} | ||||||
|
||||||
private boolean isDirExists(FsPath fsPath) throws IOException { | ||||||
return remoteFileSystem.exists(fsPath); | ||||||
} | ||||||
|
||||||
private void deleteDir(FsPath fsPath) { | ||||||
try { | ||||||
if (isDirExists(fsPath)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: just use |
||||||
remoteFileSystem.delete(fsPath, true); | ||||||
LOG.info("Delete table's remote dir {} success.", fsPath); | ||||||
} | ||||||
} catch (IOException e) { | ||||||
LOG.error("Delete table's remote dir {} failed.", fsPath, e); | ||||||
} | ||||||
} | ||||||
|
||||||
private FsPath tableKvDir(TablePath tablePath, long tableId) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return FlussPaths.remoteTableDir(remoteKvDir, tablePath, tableId); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.fluss.server.coordinator; | ||
|
||
import com.alibaba.fluss.config.ConfigOptions; | ||
import com.alibaba.fluss.config.Configuration; | ||
import com.alibaba.fluss.metadata.TablePath; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comments for this class... Otherwise, checkstyle will fail |
||
public class RemoteStorageHandlerTest { | ||
|
||
private static @TempDir Path tempDir; | ||
|
||
private static RemoteStorageHandler remoteStorageHandler; | ||
|
||
@BeforeAll | ||
static void before() throws IOException { | ||
Configuration conf = new Configuration(); | ||
conf.setString(ConfigOptions.REMOTE_DATA_DIR, tempDir.toString()); | ||
remoteStorageHandler = new RemoteStorageHandler(conf); | ||
} | ||
|
||
@Test | ||
void testDeleteRemoteByTablePath() throws IOException { | ||
TablePath tablePath = TablePath.of("ods", "tbl"); | ||
remoteStorageHandler.createTableKvDir(tablePath, 0); | ||
assertThat(remoteStorageHandler.isTableKvDirExists(tablePath, 0)).isTrue(); | ||
remoteStorageHandler.deleteTable(tablePath, 0); | ||
assertThat(remoteStorageHandler.isTableKvDirExists(tablePath, 0)).isFalse(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: