Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -433,6 +433,27 @@ public void testRecoverWrongFile() throws Exception {
}
}

@Test
public void testRecoveryWithoutBlocks() throws Exception {
RootedOzoneFileSystem fs = (RootedOzoneFileSystem)FileSystem.get(conf);

final FSDataOutputStream stream = fs.create(file, true);
try {
stream.hsync();
assertFalse(fs.isFileClosed(file));

int count = 0;
while (count++ < 15 && !fs.recoverLease(file)) {
Thread.sleep(1000);
}
// The lease should have been recovered.
assertTrue(fs.isFileClosed(file), "File should be closed");

} finally {
closeIgnoringKeyNotFound(stream);
}
}

private void verifyData(byte[] data, int dataSize, Path filePath, RootedOzoneFileSystem fs) throws IOException {
try (FSDataInputStream fdis = fs.open(filePath)) {
int bufferSize = dataSize > data.length ? dataSize / 2 : dataSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,31 @@ private RecoverLeaseResponse doWork(OzoneManager ozoneManager,
List<OmKeyLocationInfo> keyLocationInfoList = keyLatestVersionLocations.getLocationList();
OmKeyLocationInfoGroup openKeyLatestVersionLocations = openKeyInfo.getLatestVersionLocations();
List<OmKeyLocationInfo> openKeyLocationInfoList = openKeyLatestVersionLocations.getLocationList();
OmKeyLocationInfo finalBlock;

OmKeyLocationInfo finalBlock = null;
boolean returnKeyInfo = true;
if (openKeyLocationInfoList.size() > keyLocationInfoList.size() &&
openKeyModificationTime > keyInfo.getModificationTime()) {
openKeyModificationTime > keyInfo.getModificationTime() &&
openKeyLocationInfoList.size() > 0) {
finalBlock = openKeyLocationInfoList.get(openKeyLocationInfoList.size() - 1);
returnKeyInfo = false;
} else {
} else if (keyLocationInfoList.size() > 0) {
finalBlock = keyLocationInfoList.get(keyLocationInfoList.size() - 1);
}

// set token to last block if enabled
if (ozoneManager.isGrpcBlockTokenEnabled()) {
String remoteUser = getRemoteUser().getShortUserName();
OzoneBlockTokenSecretManager secretManager = ozoneManager.getBlockTokenSecretManager();
finalBlock.setToken(secretManager.generateToken(remoteUser, finalBlock.getBlockID(),
EnumSet.of(READ, WRITE), finalBlock.getLength()));
if (finalBlock != null) {
// set token to last block if enabled
if (ozoneManager.isGrpcBlockTokenEnabled()) {
String remoteUser = getRemoteUser().getShortUserName();
OzoneBlockTokenSecretManager secretManager = ozoneManager.getBlockTokenSecretManager();
finalBlock.setToken(secretManager.generateToken(remoteUser, finalBlock.getBlockID(),
EnumSet.of(READ, WRITE), finalBlock.getLength()));
}
// refresh last block pipeline
ContainerWithPipeline containerWithPipeline =
ozoneManager.getScmClient().getContainerClient().getContainerWithPipeline(finalBlock.getContainerID());
finalBlock.setPipeline(containerWithPipeline.getPipeline());
}

// refresh last block pipeline
ContainerWithPipeline containerWithPipeline =
ozoneManager.getScmClient().getContainerClient().getContainerWithPipeline(finalBlock.getContainerID());
finalBlock.setPipeline(containerWithPipeline.getPipeline());

RecoverLeaseResponse.Builder rb = RecoverLeaseResponse.newBuilder();
rb.setKeyInfo(returnKeyInfo ? keyInfo.getNetworkProtobuf(getOmRequest().getVersion(), true) :
openKeyInfo.getNetworkProtobuf(getOmRequest().getVersion(), true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,17 @@ public boolean recoverLease(Path f) throws IOException {

// finalize the final block and get block length
List<OmKeyLocationInfo> locationInfoList = keyInfo.getLatestVersionLocations().getLocationList();
OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
if (!locationInfoList.isEmpty()) {
OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}

// recover and commit file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,17 @@ public boolean recoverLease(final Path f) throws IOException {

// finalize the final block and get block length
List<OmKeyLocationInfo> locationInfoList = keyInfo.getLatestVersionLocations().getLocationList();
OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
if (!locationInfoList.isEmpty()) {
OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}

// recover and commit file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,17 @@ public boolean recoverLease(Path f) throws IOException {

// finalize the final block and get block length
List<OmKeyLocationInfo> locationInfoList = keyInfo.getLatestVersionLocations().getLocationList();
OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
if (!locationInfoList.isEmpty()) {
OmKeyLocationInfo block = locationInfoList.get(locationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}

// recover and commit file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,17 @@ public boolean recoverLease(final Path f) throws IOException {

// finalize the final block and get block length
List<OmKeyLocationInfo> keyLocationInfoList = keyInfo.getLatestVersionLocations().getLocationList();
OmKeyLocationInfo block = keyLocationInfoList.get(keyLocationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
if (!keyLocationInfoList.isEmpty()) {
OmKeyLocationInfo block = keyLocationInfoList.get(keyLocationInfoList.size() - 1);
try {
block.setLength(getAdapter().finalizeBlock(block));
} catch (Throwable e) {
if (!forceRecovery) {
throw e;
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}
LOG.warn("Failed to finalize block. Continue to recover the file since {} is enabled.",
FORCE_LEASE_RECOVERY_ENV, e);
}

// recover and commit file
Expand Down