HBASE-11650 Write hbase.id to a temporary location and move into place
This commit is contained in:
parent
db15d6e6a7
commit
543c64d2e9
|
@ -787,15 +787,28 @@ public abstract class FSUtils {
|
||||||
int wait) throws IOException {
|
int wait) throws IOException {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
Path filePath = new Path(rootdir, HConstants.CLUSTER_ID_FILE_NAME);
|
Path idFile = new Path(rootdir, HConstants.CLUSTER_ID_FILE_NAME);
|
||||||
FSDataOutputStream s = fs.create(filePath);
|
Path tempIdFile = new Path(rootdir, HConstants.HBASE_TEMP_DIRECTORY +
|
||||||
|
Path.SEPARATOR + HConstants.CLUSTER_ID_FILE_NAME);
|
||||||
|
// Write the id file to a temporary location
|
||||||
|
FSDataOutputStream s = fs.create(tempIdFile);
|
||||||
try {
|
try {
|
||||||
s.write(clusterId.toByteArray());
|
s.write(clusterId.toByteArray());
|
||||||
} finally {
|
|
||||||
s.close();
|
s.close();
|
||||||
|
s = null;
|
||||||
|
// Move the temporary file to its normal location. Throw an IOE if
|
||||||
|
// the rename failed
|
||||||
|
if (!fs.rename(tempIdFile, idFile)) {
|
||||||
|
throw new IOException("Unable to move temp version file to " + idFile);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// Attempt to close the stream if still open on the way out
|
||||||
|
try {
|
||||||
|
if (s != null) s.close();
|
||||||
|
} catch (IOException ignore) { }
|
||||||
}
|
}
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Created cluster ID file at " + filePath.toString() + " with ID: " + clusterId);
|
LOG.debug("Created cluster ID file at " + idFile.toString() + " with ID: " + clusterId);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
|
Loading…
Reference in New Issue