use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.
the class PersistentLocalResourceRepository method get.
@Override
public LocalResource get(String relativePath) throws HyracksDataException {
LocalResource resource = resourceCache.getIfPresent(relativePath);
if (resource == null) {
FileReference resourceFile = getLocalResourceFileByName(ioManager, relativePath);
if (resourceFile.getFile().exists()) {
resource = readLocalResource(resourceFile.getFile());
resourceCache.put(relativePath, resource);
}
}
return resource;
}
use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.
the class PersistentLocalResourceRepository method getIndexFileRef.
public IndexFileProperties getIndexFileRef(String absoluteFilePath) throws HyracksDataException {
//TODO pass relative path
final String[] tokens = absoluteFilePath.split(File.separator);
if (tokens.length < 5) {
throw new HyracksDataException("Invalid file format");
}
String fileName = tokens[tokens.length - 1];
String index = tokens[tokens.length - 2];
String dataverse = tokens[tokens.length - 3];
String partition = tokens[tokens.length - 4];
int partitionId = StoragePathUtil.getPartitionNumFromName(partition);
String relativePath = getLocalResourceRelativePath(absoluteFilePath);
final LocalResource lr = get(relativePath);
int datasetId = lr == null ? -1 : ((DatasetLocalResource) lr.getResource()).getDatasetId();
return new IndexFileProperties(partitionId, dataverse, index, fileName, datasetId);
}
use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.
the class PersistentLocalResourceRepository method loadAndGetAllResources.
public Map<Long, LocalResource> loadAndGetAllResources() throws IOException {
//TODO During recovery, the memory usage currently is proportional to the number of resources available.
//This could be fixed by traversing all resources on disk until the required resource is found.
LOGGER.log(Level.INFO, "Loading all resources");
Map<Long, LocalResource> resourcesMap = new HashMap<>();
for (int i = 0; i < mountPoints.length; i++) {
File storageRootDir = getStorageRootDirectoryIfExists(ioManager, nodeId, i);
if (storageRootDir == null) {
LOGGER.log(Level.INFO, "Getting storage root dir returned null. Returning");
continue;
}
LOGGER.log(Level.INFO, "Getting storage root dir returned " + storageRootDir.getAbsolutePath());
//load all local resources.
File[] partitions = storageRootDir.listFiles();
LOGGER.log(Level.INFO, "Number of partitions found = " + partitions.length);
for (File partition : partitions) {
File[] dataverseFileList = partition.listFiles();
LOGGER.log(Level.INFO, "Reading partition = " + partition.getName() + ". Number of dataverses found: " + dataverseFileList.length);
if (dataverseFileList != null) {
for (File dataverseFile : dataverseFileList) {
loadDataverse(dataverseFile, resourcesMap);
}
}
}
}
return resourcesMap;
}
use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.
the class PersistentLocalResourceRepository method getMaxResourceIdForIndex.
private long getMaxResourceIdForIndex(File indexFile, long maxSoFar) throws HyracksDataException {
long maxResourceId = maxSoFar;
if (indexFile.isDirectory()) {
File[] metadataFiles = indexFile.listFiles(METADATA_FILES_FILTER);
if (metadataFiles != null) {
for (File metadataFile : metadataFiles) {
LocalResource localResource = readLocalResource(metadataFile);
maxResourceId = Math.max(maxResourceId, localResource.getId());
}
}
}
return maxResourceId;
}
use of org.apache.hyracks.storage.common.LocalResource in project asterixdb by apache.
the class ReplicaResourcesManager method getLaggingReplicaIndexesId2PathMap.
public Map<Long, String> getLaggingReplicaIndexesId2PathMap(String replicaId, long targetLSN) throws IOException {
Map<Long, String> laggingReplicaIndexes = new HashMap<Long, String>();
try {
//for every index in replica
Set<File> remoteIndexes = getReplicaIndexes(replicaId);
for (File indexFolder : remoteIndexes) {
if (getReplicaIndexMaxLSN(indexFolder) < targetLSN) {
File localResource = new File(indexFolder + File.separator + PersistentLocalResourceRepository.METADATA_FILE_NAME);
LocalResource resource = PersistentLocalResourceRepository.readLocalResource(localResource);
laggingReplicaIndexes.put(resource.getId(), indexFolder.getAbsolutePath());
}
}
} catch (HyracksDataException e) {
e.printStackTrace();
}
return laggingReplicaIndexes;
}
Aggregations