use of org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException in project accumulo by apache.
the class BulkImportMove method call.
@Override
public Repo<Manager> call(long tid, Manager manager) throws Exception {
final Path bulkDir = new Path(bulkInfo.bulkDir);
final Path sourceDir = new Path(bulkInfo.sourceDir);
String fmtTid = FateTxId.formatTid(tid);
log.debug("{} sourceDir {}", fmtTid, sourceDir);
VolumeManager fs = manager.getVolumeManager();
if (bulkInfo.tableState == TableState.ONLINE) {
ZooArbitrator.start(manager.getContext(), Constants.BULK_ARBITRATOR_TYPE, tid);
}
try {
manager.updateBulkImportStatus(sourceDir.toString(), BulkImportState.MOVING);
Map<String, String> oldToNewNameMap = BulkSerialize.readRenameMap(bulkDir.toString(), fs::open);
moveFiles(tid, sourceDir, bulkDir, manager, fs, oldToNewNameMap);
return new LoadFiles(bulkInfo);
} catch (Exception ex) {
throw new AcceptableThriftTableOperationException(bulkInfo.tableId.canonical(), null, TableOperation.BULK_IMPORT, TableOperationExceptionType.BULK_BAD_INPUT_DIRECTORY, bulkInfo.sourceDir + ": " + ex);
}
}
use of org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException in project accumulo by apache.
the class BulkImportMove method moveFiles.
/**
* For every entry in renames, move the file from the key path to the value path
*/
private void moveFiles(long tid, Path sourceDir, Path bulkDir, Manager manager, final VolumeManager fs, Map<String, String> renames) throws Exception {
MetadataTableUtil.addBulkLoadInProgressFlag(manager.getContext(), "/" + bulkDir.getParent().getName() + "/" + bulkDir.getName(), tid);
AccumuloConfiguration aConf = manager.getConfiguration();
@SuppressWarnings("deprecation") int workerCount = aConf.getCount(aConf.resolve(Property.MANAGER_RENAME_THREADS, Property.MANAGER_BULK_RENAME_THREADS));
Map<Path, Path> oldToNewMap = new HashMap<>();
String fmtTid = FateTxId.formatTid(tid);
for (Map.Entry<String, String> renameEntry : renames.entrySet()) {
final Path originalPath = new Path(sourceDir, renameEntry.getKey());
Path newPath = new Path(bulkDir, renameEntry.getValue());
oldToNewMap.put(originalPath, newPath);
}
try {
fs.bulkRename(oldToNewMap, workerCount, "bulkDir move", fmtTid);
} catch (IOException ioe) {
throw new AcceptableThriftTableOperationException(bulkInfo.tableId.canonical(), null, TableOperation.BULK_IMPORT, TableOperationExceptionType.OTHER, ioe.getCause().getMessage());
}
}
use of org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException in project accumulo by apache.
the class MoveExportedFiles method call.
@Override
public Repo<Manager> call(long tid, Manager manager) throws Exception {
String fmtTid = FateTxId.formatTid(tid);
int workerCount = manager.getConfiguration().getCount(Property.MANAGER_RENAME_THREADS);
VolumeManager fs = manager.getVolumeManager();
Map<Path, Path> oldToNewPaths = new HashMap<>();
for (ImportedTableInfo.DirectoryMapping dm : tableInfo.directories) {
Map<String, String> fileNameMappings = new HashMap<>();
PopulateMetadataTable.readMappingFile(fs, tableInfo, dm.importDir, fileNameMappings);
FileStatus[] exportedFiles = fs.listStatus(new Path(dm.exportDir));
FileStatus[] importedFiles = fs.listStatus(new Path(dm.importDir));
Function<FileStatus, String> fileStatusName = fstat -> fstat.getPath().getName();
Set<String> importing = Arrays.stream(exportedFiles).map(fileStatusName).map(fileNameMappings::get).collect(Collectors.toSet());
Set<String> imported = Arrays.stream(importedFiles).map(fileStatusName).collect(Collectors.toSet());
if (log.isDebugEnabled()) {
log.debug("{} files already present in imported (target) directory: {}", fmtTid, String.join(",", imported));
}
Set<String> missingFiles = Sets.difference(new HashSet<>(fileNameMappings.values()), new HashSet<>(Sets.union(importing, imported)));
if (!missingFiles.isEmpty()) {
throw new AcceptableThriftTableOperationException(tableInfo.tableId.canonical(), tableInfo.tableName, TableOperation.IMPORT, TableOperationExceptionType.OTHER, "Missing source files corresponding to files " + String.join(",", missingFiles));
}
for (FileStatus fileStatus : exportedFiles) {
Path originalPath = fileStatus.getPath();
String newName = fileNameMappings.get(originalPath.getName());
// Need to exclude any other files which may be present in the exported directory
if (newName != null) {
Path newPath = new Path(dm.importDir, newName);
// No try-catch here, as we do not expect any "benign" exceptions. Prior code already
// accounts for files which were already moved. So anything returned by the rename
// operation would be truly unexpected
oldToNewPaths.put(originalPath, newPath);
} else {
log.debug("{} not moving (unmapped) file {}", fmtTid, originalPath);
}
}
}
try {
fs.bulkRename(oldToNewPaths, workerCount, "importtable rename", fmtTid);
} catch (IOException ioe) {
throw new AcceptableThriftTableOperationException(tableInfo.tableId.canonical(), null, TableOperation.IMPORT, TableOperationExceptionType.OTHER, ioe.getCause().getMessage());
}
return new FinishImportTable(tableInfo);
}
use of org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException in project accumulo by apache.
the class CompactRange method call.
@Override
public Repo<Manager> call(final long tid, Manager env) throws Exception {
String zTablePath = Constants.ZROOT + "/" + env.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_ID;
ZooReaderWriter zoo = env.getContext().getZooReaderWriter();
byte[] cid;
try {
cid = zoo.mutateExisting(zTablePath, currentValue -> {
String cvs = new String(currentValue, UTF_8);
String[] tokens = cvs.split(",");
long flushID = Long.parseLong(tokens[0]) + 1;
String txidString = String.format("%016x", tid);
for (int i = 1; i < tokens.length; i++) {
if (tokens[i].startsWith(txidString))
// skip self
continue;
log.debug("txidString : {}", txidString);
log.debug("tokens[{}] : {}", i, tokens[i]);
throw new AcceptableThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Another compaction with iterators and/or a compaction strategy is running");
}
StringBuilder encodedIterators = new StringBuilder();
if (config != null) {
Hex hex = new Hex();
encodedIterators.append(",");
encodedIterators.append(txidString);
encodedIterators.append("=");
encodedIterators.append(new String(hex.encode(config), UTF_8));
}
return (Long.toString(flushID) + encodedIterators).getBytes(UTF_8);
});
return new CompactionDriver(Long.parseLong(new String(cid, UTF_8).split(",")[0]), namespaceId, tableId, startRow, endRow);
} catch (NoNodeException nne) {
throw new AcceptableThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null);
}
}
use of org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException in project accumulo by apache.
the class RenameNamespace method call.
@Override
public Repo<Manager> call(long id, Manager manager) throws Exception {
ZooReaderWriter zoo = manager.getContext().getZooReaderWriter();
Utils.getTableNameLock().lock();
try {
Utils.checkNamespaceDoesNotExist(manager.getContext(), newName, namespaceId, TableOperation.RENAME);
final String tap = manager.getZooKeeperRoot() + Constants.ZNAMESPACES + "/" + namespaceId + Constants.ZNAMESPACE_NAME;
zoo.mutateExisting(tap, current -> {
final String currentName = new String(current, UTF_8);
if (currentName.equals(newName))
// assume in this case the operation is running again, so we are done
return null;
if (!currentName.equals(oldName)) {
throw new AcceptableThriftTableOperationException(null, oldName, TableOperation.RENAME, TableOperationExceptionType.NAMESPACE_NOTFOUND, "Name changed while processing");
}
return newName.getBytes(UTF_8);
});
manager.getContext().clearTableListCache();
} finally {
Utils.getTableNameLock().unlock();
Utils.unreserveNamespace(manager, namespaceId, id, true);
}
LoggerFactory.getLogger(RenameNamespace.class).debug("Renamed namespace {} {} {}", namespaceId, oldName, newName);
return null;
}
Aggregations