nextId = nextId.add(BigInteger.ONE);
final String nextIdString = nextId.toString(Character.MAX_RADIX);
ZooSession.getSession().setData(ntp, nextIdString.getBytes(), stat.getVersion());
} catch (Exception e1) {
log.error("Failed to assign tableId to " + tableName, e1);
throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE, TableOperationExceptionType.OTHER, e1.getMessage());
}
// write tableName & tableId to zookeeper
try {
TableManager.getInstance().addTable(tableId, tableName);
Tables.clearCache(instance);
} catch (Exception e2) {
log.error("Failed to create table " + tableName, e2);
throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE, TableOperationExceptionType.OTHER, e2.getMessage());
}
}
for (Entry<String,String> entry : aggregators.entrySet()) {
setTableProperty(null, SecurityConstants.systemCredentials, tableName, entry.getKey(), entry.getValue());
}
log.info(String.format("Creating table %s with tableId %s and %d splitPoints", tableName, tableId, splitPoints.size()));
try {
if (splitPoints.isEmpty()) {
final Text tablet = null;
final String dir = Constants.getTablesDir() + "/" + tableId;
createNewTableTabletDirectories(fs, dir, Collections.singletonList(tablet));
KeyExtent extent = new KeyExtent(new Text(tableId), null, null);
MetadataTable.addTablet(extent, Constants.DEFAULT_TABLET_LOCATION, SecurityConstants.systemCredentials, TabletTime.getTimeID(timeType), masterLock);
newly_created_tablets++;
} else {
Text previous = null;
splitPoints.add(null);
final ArrayList<Text> splitPointsText = new ArrayList<Text>(splitPoints.size());
for (byte[] splitpoint : splitPoints) {
if (splitpoint != null) {
splitPointsText.add(new Text(splitpoint));
} else {
splitPointsText.add(null);
}
}
final String dir = Constants.getTablesDir() + "/" + tableId;
final Map<Text,String> tabletDirs = createNewTableTabletDirectories(fs, dir, splitPointsText);
for (Text splitpointText : splitPointsText) {
String datafiles = null;
if (splitpointText != null) {
datafiles = tabletDirs.get(splitpointText);
} else {
datafiles = Constants.DEFAULT_TABLET_LOCATION;
}
final KeyExtent local_newExtent = new KeyExtent(new Text(tableId), splitpointText, previous);
fs.mkdirs(new Path(Constants.getTablesDir() + "/" + tableId + datafiles));
MetadataTable.addTablet(local_newExtent, datafiles, SecurityConstants.systemCredentials, TabletTime.getTimeID(timeType), masterLock);
previous = splitpointText;
newly_created_tablets++;
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new ThriftTableOperationException(tableId, tableName, TableOperation.CREATE, TableOperationExceptionType.OTHER, e.getMessage());
}
// give all table permissions to the creator
for (TablePermission permission : TablePermission.values()) {
try {