-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-factor and cleanup Coop Lock implementation (#204)
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v3.0.0-RC01
- v2.2.26
- v2.2.25
- v2.2.24
- v2.2.23
- v2.2.22
- v2.2.21
- v2.2.20
- v2.2.19
- v2.2.18
- v2.2.17
- v2.2.16
- v2.2.15
- v2.2.14
- v2.2.13
- v2.2.12
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v2.0.0-RC2
- 2.2.17
- 2.2.16
- 2.2.15
- 2.2.14
- 2.2.13
- 2.2.12
Showing
15 changed files
with
1,126 additions
and
641 deletions.
There are no files selected for viewing
380 changes: 26 additions & 354 deletions
380
gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/CoopLockFsck.java
Large diffs are not rendered by default.
Oops, something went wrong.
443 changes: 443 additions & 0 deletions
443
gcs/src/main/java/com/google/cloud/hadoop/fs/gcs/CoopLockFsckRunner.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
gcsio/src/main/java/com/google/cloud/hadoop/gcsio/cooplock/CoopLockOperationDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2019 Google LLC. All Rights Reserved. | ||
* | ||
* 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.google.cloud.hadoop.gcsio.cooplock; | ||
|
||
import static com.google.cloud.hadoop.gcsio.cooplock.CoopLockOperationType.DELETE; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
import com.google.cloud.hadoop.gcsio.FileInfo; | ||
import com.google.cloud.hadoop.gcsio.ForwardingGoogleCloudStorage; | ||
import com.google.cloud.hadoop.gcsio.GoogleCloudStorage; | ||
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl; | ||
import com.google.cloud.hadoop.gcsio.PathCodec; | ||
import com.google.cloud.hadoop.gcsio.StorageResourceId; | ||
import com.google.common.base.MoreObjects; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.concurrent.Future; | ||
|
||
public class CoopLockOperationDelete { | ||
|
||
private final String operationId = UUID.randomUUID().toString(); | ||
private final Instant operationInstant = Instant.now(); | ||
|
||
private final StorageResourceId resourceId; | ||
|
||
private final CoopLockRecordsDao coopLockRecordsDao; | ||
private final CoopLockOperationDao coopLockOperationDao; | ||
|
||
private Future<?> lockUpdateFuture; | ||
|
||
private CoopLockOperationDelete( | ||
GoogleCloudStorageImpl gcs, PathCodec pathCodec, StorageResourceId resourceId) { | ||
this.resourceId = resourceId; | ||
this.coopLockRecordsDao = new CoopLockRecordsDao(gcs); | ||
this.coopLockOperationDao = new CoopLockOperationDao(gcs, pathCodec); | ||
} | ||
|
||
public static CoopLockOperationDelete create( | ||
GoogleCloudStorage gcs, PathCodec pathCodec, URI path) { | ||
while (gcs instanceof ForwardingGoogleCloudStorage) { | ||
gcs = ((ForwardingGoogleCloudStorage) gcs).getDelegate(); | ||
} | ||
checkArgument( | ||
gcs instanceof GoogleCloudStorageImpl, | ||
"gcs should be instance of %s, but was %s", | ||
GoogleCloudStorageImpl.class, | ||
gcs.getClass()); | ||
return new CoopLockOperationDelete( | ||
(GoogleCloudStorageImpl) gcs, | ||
pathCodec, | ||
pathCodec.validatePathAndGetId(path, /* allowEmptyObjectName= */ true)); | ||
} | ||
|
||
public void lock() { | ||
try { | ||
coopLockRecordsDao.lockPaths(operationId, operationInstant, DELETE, resourceId); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format("Failed to acquire lock for %s operation", this), e); | ||
} | ||
} | ||
|
||
public void persistAndScheduleRenewal( | ||
List<FileInfo> itemsToDelete, List<FileInfo> bucketsToDelete) { | ||
try { | ||
lockUpdateFuture = | ||
coopLockOperationDao.persistDeleteOperation( | ||
operationId, operationInstant, resourceId, itemsToDelete, bucketsToDelete); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format("Failed to persist %s operation", this), e); | ||
} | ||
} | ||
|
||
public void unlock() { | ||
try { | ||
coopLockRecordsDao.unlockPaths(operationId, resourceId); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format("Failed to release lock for %s operation", this), e); | ||
} | ||
} | ||
|
||
public void cancelRenewal() { | ||
lockUpdateFuture.cancel(/* mayInterruptIfRunning= */ true); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("operationId", operationId) | ||
.add("operationInstant", operationInstant) | ||
.add("resourceId", resourceId) | ||
.toString(); | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
gcsio/src/main/java/com/google/cloud/hadoop/gcsio/cooplock/CoopLockOperationRename.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright 2019 Google LLC. All Rights Reserved. | ||
* | ||
* 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.google.cloud.hadoop.gcsio.cooplock; | ||
|
||
import static com.google.cloud.hadoop.gcsio.cooplock.CoopLockOperationType.RENAME; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
import com.google.cloud.hadoop.gcsio.FileInfo; | ||
import com.google.cloud.hadoop.gcsio.ForwardingGoogleCloudStorage; | ||
import com.google.cloud.hadoop.gcsio.GoogleCloudStorage; | ||
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl; | ||
import com.google.cloud.hadoop.gcsio.PathCodec; | ||
import com.google.cloud.hadoop.gcsio.StorageResourceId; | ||
import com.google.common.base.MoreObjects; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.time.Instant; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.Future; | ||
|
||
public class CoopLockOperationRename { | ||
|
||
private final String operationId = UUID.randomUUID().toString(); | ||
private final Instant operationInstant = Instant.now(); | ||
|
||
private final StorageResourceId srcResourceId; | ||
private final StorageResourceId dstResourceId; | ||
|
||
private final CoopLockRecordsDao coopLockRecordsDao; | ||
private final CoopLockOperationDao coopLockOperationDao; | ||
|
||
private Future<?> lockUpdateFuture; | ||
|
||
private CoopLockOperationRename( | ||
GoogleCloudStorageImpl gcs, | ||
PathCodec pathCodec, | ||
StorageResourceId srcResourceId, | ||
StorageResourceId dstResourceId) { | ||
this.srcResourceId = srcResourceId; | ||
this.dstResourceId = dstResourceId; | ||
this.coopLockRecordsDao = new CoopLockRecordsDao(gcs); | ||
this.coopLockOperationDao = new CoopLockOperationDao(gcs, pathCodec); | ||
} | ||
|
||
public static CoopLockOperationRename create( | ||
GoogleCloudStorage gcs, PathCodec pathCodec, URI src, URI dst) { | ||
while (gcs instanceof ForwardingGoogleCloudStorage) { | ||
gcs = ((ForwardingGoogleCloudStorage) gcs).getDelegate(); | ||
} | ||
checkArgument( | ||
gcs instanceof GoogleCloudStorageImpl, | ||
"gcs should be instance of %s, but was %s", | ||
GoogleCloudStorageImpl.class, | ||
gcs.getClass()); | ||
return new CoopLockOperationRename( | ||
(GoogleCloudStorageImpl) gcs, | ||
pathCodec, | ||
pathCodec.validatePathAndGetId(src, /* allowEmptyObjectName= */ true), | ||
pathCodec.validatePathAndGetId(dst, /* allowEmptyObjectName= */ true)); | ||
} | ||
|
||
public void lock() { | ||
try { | ||
coopLockRecordsDao.lockPaths( | ||
operationId, operationInstant, RENAME, srcResourceId, dstResourceId); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format("Failed to acquire lock %s operation", this), e); | ||
} | ||
} | ||
|
||
public void persistAndScheduleRenewal( | ||
Map<FileInfo, URI> srcToDstItemNames, Map<FileInfo, URI> srcToDstMarkerItemNames) { | ||
try { | ||
lockUpdateFuture = | ||
coopLockOperationDao.persistRenameOperation( | ||
operationId, | ||
operationInstant, | ||
srcResourceId, | ||
dstResourceId, | ||
srcToDstItemNames, | ||
srcToDstMarkerItemNames); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format("Failed to persist %s operation", this), e); | ||
} | ||
} | ||
|
||
public void checkpoint() { | ||
try { | ||
coopLockOperationDao.checkpointRenameOperation( | ||
srcResourceId, dstResourceId, operationId, operationInstant, /* copySucceeded= */ true); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format("Failed to checkpoint %s operation", this), e); | ||
} | ||
} | ||
|
||
public void unlock() { | ||
try { | ||
coopLockRecordsDao.unlockPaths(operationId, srcResourceId, dstResourceId); | ||
} catch (IOException e) { | ||
throw new RuntimeException( | ||
String.format("Failed to release unlock for %s operation", this), e); | ||
} | ||
} | ||
|
||
public void cancelRenewal() { | ||
lockUpdateFuture.cancel(/* mayInterruptIfRunning= */ true); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("operationId", operationId) | ||
.add("operationInstant", operationInstant) | ||
.add("srcResourceId", srcResourceId) | ||
.add("dstResourceId", dstResourceId) | ||
.toString(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
gcsio/src/main/java/com/google/cloud/hadoop/gcsio/cooplock/CoopLockOperationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2019 Google LLC. All Rights Reserved. | ||
* | ||
* 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.google.cloud.hadoop.gcsio.cooplock; | ||
|
||
/** Enum that represent cooperative locking operation type */ | ||
public enum CoopLockOperationType { | ||
RENAME, | ||
DELETE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
gcsio/src/main/java/com/google/cloud/hadoop/gcsio/cooplock/DeleteOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
gcsio/src/main/java/com/google/cloud/hadoop/gcsio/cooplock/RenameOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters