Skip to content
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

HDDS-2048: State check during container state transition in datanode should be lock protected #1375

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
import org.slf4j.LoggerFactory;

/**
* Class to perform KeyValue Container operations.
* Class to perform KeyValue Container operations. Any modifications to
* KeyValueContainer object should ideally be done via api exposed in
* KeyValueHandler class.
*/
public class KeyValueContainer implements Container<KeyValueContainerData> {

Expand Down Expand Up @@ -525,6 +527,8 @@ public boolean hasReadLock() {
* Acquire write lock.
*/
public void writeLock() {
// TODO: The lock for KeyValueContainer object should not be exposed
// publicly.
this.lock.writeLock().lock();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,16 +889,19 @@ public Container importContainer(long containerID, long maxSize,
@Override
public void markContainerForClose(Container container)
throws IOException {
container.writeLock();
// Move the container to CLOSING state only if it's OPEN
if (container.getContainerState() == State.OPEN) {
container.markContainerForClose();
sendICR(container);
}
container.writeUnlock();
}

@Override
public void markContainerUnhealthy(Container container)
throws IOException {
container.writeLock();
if (container.getContainerState() != State.UNHEALTHY) {
try {
container.markContainerUnhealthy();
Expand All @@ -912,11 +915,13 @@ public void markContainerUnhealthy(Container container)
sendICR(container);
}
}
container.writeUnlock();
}

@Override
public void quasiCloseContainer(Container container)
throws IOException {
container.writeLock();
final State state = container.getContainerState();
// Quasi close call is idempotent.
if (state == State.QUASI_CLOSED) {
Expand All @@ -932,11 +937,13 @@ public void quasiCloseContainer(Container container)
}
container.quasiClose();
sendICR(container);
container.writeUnlock();
}

@Override
public void closeContainer(Container container)
throws IOException {
container.writeLock();
final State state = container.getContainerState();
// Close call is idempotent.
if (state == State.CLOSED) {
Expand All @@ -958,6 +965,7 @@ public void closeContainer(Container container)
}
container.close();
sendICR(container);
container.writeUnlock();
}

@Override
Expand Down