HBASE-11987 Make zk-less table states backward compatible (Andrey Stepachev)
This commit is contained in:
parent
cc6fe16e59
commit
43a8dea347
|
@ -596,17 +596,32 @@ public class FSTableDescriptors implements TableDescriptors {
|
||||||
try {
|
try {
|
||||||
td = TableDescriptor.parseFrom(content);
|
td = TableDescriptor.parseFrom(content);
|
||||||
} catch (DeserializationException e) {
|
} catch (DeserializationException e) {
|
||||||
throw new IOException("content=" + Bytes.toShort(content), e);
|
// we have old HTableDescriptor here
|
||||||
|
try {
|
||||||
|
HTableDescriptor htd = HTableDescriptor.parseFrom(content);
|
||||||
|
LOG.warn("Found old table descriptor, converting to new format for table " +
|
||||||
|
htd.getTableName() + "; NOTE table will be in ENABLED state!");
|
||||||
|
td = new TableDescriptor(htd, TableState.State.ENABLED);
|
||||||
|
if (rewritePb) rewriteTableDescriptor(fs, status, td);
|
||||||
|
} catch (DeserializationException e1) {
|
||||||
|
throw new IOException("content=" + Bytes.toShort(content), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (rewritePb && !ProtobufUtil.isPBMagicPrefix(content)) {
|
if (rewritePb && !ProtobufUtil.isPBMagicPrefix(content)) {
|
||||||
// Convert the file over to be pb before leaving here.
|
// Convert the file over to be pb before leaving here.
|
||||||
Path tableInfoDir = status.getPath().getParent();
|
rewriteTableDescriptor(fs, status, td);
|
||||||
Path tableDir = tableInfoDir.getParent();
|
|
||||||
writeTableDescriptor(fs, td, tableDir, status);
|
|
||||||
}
|
}
|
||||||
return td;
|
return td;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void rewriteTableDescriptor(final FileSystem fs, final FileStatus status,
|
||||||
|
final TableDescriptor td)
|
||||||
|
throws IOException {
|
||||||
|
Path tableInfoDir = status.getPath().getParent();
|
||||||
|
Path tableDir = tableInfoDir.getParent();
|
||||||
|
writeTableDescriptor(fs, td, tableDir, status);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update table descriptor on the file system
|
* Update table descriptor on the file system
|
||||||
* @throws IOException Thrown if failed update.
|
* @throws IOException Thrown if failed update.
|
||||||
|
|
|
@ -28,6 +28,9 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import org.apache.hadoop.fs.FSDataInputStream;
|
||||||
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||||
import org.apache.hadoop.hbase.client.TableState;
|
import org.apache.hadoop.hbase.client.TableState;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -42,6 +45,7 @@ import org.apache.hadoop.hbase.HConstants;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
import org.apache.hadoop.hbase.TableDescriptors;
|
import org.apache.hadoop.hbase.TableDescriptors;
|
||||||
import org.apache.hadoop.hbase.TableExistsException;
|
import org.apache.hadoop.hbase.TableExistsException;
|
||||||
|
import org.apache.hadoop.hbase.exceptions.DeserializationException;
|
||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -175,6 +179,30 @@ public class TestFSTableDescriptors {
|
||||||
assertTrue(td.equals(td2));
|
assertTrue(td.equals(td2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void testReadingOldHTDFromFS() throws IOException, DeserializationException {
|
||||||
|
final String name = "testReadingOldHTDFromFS";
|
||||||
|
FileSystem fs = FileSystem.get(UTIL.getConfiguration());
|
||||||
|
Path rootdir = UTIL.getDataTestDir(name);
|
||||||
|
FSTableDescriptors fstd = new FSTableDescriptors(fs, rootdir);
|
||||||
|
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name));
|
||||||
|
TableDescriptor td = new TableDescriptor(htd, TableState.State.ENABLED);
|
||||||
|
Path descriptorFile = fstd.updateTableDescriptor(td);
|
||||||
|
try (FSDataOutputStream out = fs.create(descriptorFile, true)) {
|
||||||
|
out.write(htd.toByteArray());
|
||||||
|
}
|
||||||
|
FSTableDescriptors fstd2 = new FSTableDescriptors(fs, rootdir);
|
||||||
|
TableDescriptor td2 = fstd2.getDescriptor(htd.getTableName());
|
||||||
|
assertEquals(td, td2);
|
||||||
|
FileStatus descriptorFile2 =
|
||||||
|
FSTableDescriptors.getTableInfoPath(fs, fstd2.getTableDir(htd.getTableName()));
|
||||||
|
byte[] buffer = td.toByteArray();
|
||||||
|
try (FSDataInputStream in = fs.open(descriptorFile2.getPath())) {
|
||||||
|
in.readFully(buffer);
|
||||||
|
}
|
||||||
|
TableDescriptor td3 = TableDescriptor.parseFrom(buffer);
|
||||||
|
assertEquals(td, td3);
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void testHTableDescriptors()
|
@Test public void testHTableDescriptors()
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
final String name = "testHTableDescriptors";
|
final String name = "testHTableDescriptors";
|
||||||
|
|
Loading…
Reference in New Issue