/** * @return the location of the completed logs */ public URI getCompletedLocation() { try { return URIUtils.appendPath(mLocation, COMPLETED_LOCATION); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
/** * Creates a new instance of {@link UfsJournal}. * * @param location the location for this journal * @param stateMachine the state machine to manage * @param ufs the under file system * @param quietPeriodMs the amount of time to wait to pass without seeing a new journal entry when * gaining primacy */ UfsJournal(URI location, JournalEntryStateMachine stateMachine, UnderFileSystem ufs, long quietPeriodMs) { mLocation = URIUtils.appendPathOrDie(location, VERSION); mMaster = stateMachine; mUfs = ufs; mQuietPeriodMs = quietPeriodMs; mLogDir = URIUtils.appendPathOrDie(mLocation, LOG_DIRNAME); mCheckpointDir = URIUtils.appendPathOrDie(mLocation, CHECKPOINT_DIRNAME); mTmpDir = URIUtils.appendPathOrDie(mLocation, TMP_DIRNAME); mState = State.SECONDARY; }
/** * Constructs an {@link AlluxioURI} from components. * * @param scheme the scheme of the path. e.g. alluxio, hdfs, s3, file, null, etc * @param authority the authority of the path * @param path the path component of the URI. e.g. /abc/c.txt, /a b/c/c.txt * @param queryMap the (nullable) map of key/value pairs for the query component of the URI */ public AlluxioURI(String scheme, Authority authority, String path, Map<String, String> queryMap) { mUri = URI.Factory.create(scheme, authority, path, URIUtils.generateQueryString(queryMap)); }
@Override public int hashCode() { if (mHashCode != 0) { return mHashCode; } int hashCode = URIUtils.hashIgnoreCase(0, getScheme()); if (mPath == null) { hashCode = URIUtils.hash(hashCode, mSchemeSpecificPart); } else { hashCode = URIUtils.hash(hashCode, mPath); hashCode = URIUtils.hash(hashCode, mQuery); hashCode = URIUtils.hash(hashCode, mAuthority.toString()); } mHashCode = hashCode; return hashCode; } }
@Override public boolean supportsPath(String path) { if (path == null) { return false; } return URIUtils.isLocalFilesystem(path); } }
/** * Gets the map of query parameters. * * @return the map of query parameters */ public Map<String, String> getQueryMap() { return URIUtils.parseQueryString(mUri.getQuery()); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof StandardURI)) { return false; } StandardURI that = (StandardURI) o; if (compareScheme(that) != 0) { return false; } if ((this.mPath == null && that.mPath != null) || (this.mPath != null && that.mPath == null)) { return false; } if (this.mPath == null) { return URIUtils.equals(this.mSchemeSpecificPart, that.mSchemeSpecificPart); } return URIUtils.equals(this.mPath, that.mPath) && URIUtils.equals(this.mQuery, that.mQuery) && this.mAuthority.equals(that.mAuthority); }
private void initFromBackup(AlluxioURI backup) throws IOException { UnderFileSystem ufs; if (URIUtils.isLocalFilesystem(backup.toString())) { ufs = UnderFileSystem.Factory.create("/", UnderFileSystemConfiguration.defaults(ServerConfiguration.global())); } else { ufs = UnderFileSystem.Factory.createForRoot(ServerConfiguration.global()); } try (UnderFileSystem closeUfs = ufs; InputStream ufsIn = ufs.open(backup.getPath())) { LOG.info("Initializing metadata from backup {}", backup); mBackupManager.initFromBackup(ufsIn); } }
/** * Gets the map of query parameters. * * @return the map of query parameters */ public Map<String, String> getQueryMap() { return URIUtils.parseQueryString(mUri.getQuery()); }
/** * @param logNumber the log number to get the path for * @return the location of the completed log for a particular log number */ private URI getCompletedLogV0(long logNumber) { return URIUtils .appendPathOrDie(mCompletedLogsV0, String.format("%s.%020d", "log", logNumber)); }
/** * @return the location of the journal checkpoint */ protected URI getCheckpoint() { try { return URIUtils.appendPath(mLocation, CHECKPOINT_FILENAME); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
/** * Creates a new instance of {@link DefaultMetaMaster}. * * @param blockMaster a block master handle * @param masterContext the context for Alluxio master * @param executorServiceFactory a factory for creating the executor service to use for running * maintenance threads */ DefaultMetaMaster(BlockMaster blockMaster, CoreMasterContext masterContext, ExecutorServiceFactory executorServiceFactory) { super(masterContext, new SystemClock(), executorServiceFactory); mMasterAddress = new Address().setHost(ServerConfiguration.getOrDefault(PropertyKey.MASTER_HOSTNAME, "localhost")) .setRpcPort(mPort); mBlockMaster = blockMaster; mBlockMaster.registerLostWorkerFoundListener(mWorkerConfigStore::lostNodeFound); mBlockMaster.registerWorkerLostListener(mWorkerConfigStore::handleNodeLost); mBlockMaster.registerNewWorkerConfListener(mWorkerConfigStore::registerNewConf); if (URIUtils.isLocalFilesystem(ServerConfiguration .get(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS))) { mUfs = UnderFileSystem.Factory .create("/", UnderFileSystemConfiguration.defaults()); } else { mUfs = UnderFileSystem.Factory.createForRoot(ServerConfiguration.global()); } }
/** * Constructs an {@link AlluxioURI} from components. * * @param scheme the scheme of the path. e.g. alluxio, hdfs, s3, file, null, etc * @param authority the authority of the path. e.g. localhost:19998, 203.1.2.5:8080 * @param path the path component of the URI. e.g. /abc/c.txt, /a b/c/c.txt * @param queryMap the (nullable) map of key/value pairs for the query component of the URI */ public AlluxioURI(String scheme, String authority, String path, Map<String, String> queryMap) { mUri = URI.Factory.create(scheme, authority, path, URIUtils.generateQueryString(queryMap)); }
/** * Encodes a temporary location under the temporary directory. * * @param journal the UFS journal instance* * @return the location */ static URI encodeTemporaryCheckpointFileLocation(UfsJournal journal) { return URIUtils.appendPathOrDie(journal.getTmpDir(), UUID.randomUUID().toString()); }
/** * @return the location of the current log */ public URI getCurrentLog() { try { return URIUtils.appendPath(mLocation, ENTRY_LOG_FILENAME_BASE + CURRENT_LOG_EXTENSION); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
private void initFromBackup(AlluxioURI backup) throws IOException { UnderFileSystem ufs; if (URIUtils.isLocalFilesystem(backup.toString())) { ufs = UnderFileSystem.Factory.create("/", UnderFileSystemConfiguration.defaults()); } else { ufs = UnderFileSystem.Factory.createForRoot(); } try (UnderFileSystem closeUfs = ufs; InputStream ufsIn = ufs.open(backup.getPath())) { LOG.info("Initializing metadata from backup {}", backup); mBackupManager.initFromBackup(ufsIn); } }
/** * Encodes a checkpoint location under the checkpoint directory. * * @param journal the UFS journal instance * @param end the end sequence number (exclusive) * @return the location */ static URI encodeCheckpointFileLocation(UfsJournal journal, long end) { String filename = String.format("0x%x-0x%x", 0, end); URI location = URIUtils.appendPathOrDie(journal.getCheckpointDir(), filename); return location; }
/** * Appends the given path to the given base URI. It throws an {@link RuntimeException} if * the inputs are malformed. * * @param base the base URI * @param path the path to append * @return the URI resulting from appending the base and the path */ public static URI appendPathOrDie(URI base, String path) { try { return appendPath(base, path); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
/** * Encodes a log location under the log directory. * * @param journal the UFS journal instance * @param start the start sequence number (inclusive) * @param end the end sequence number (exclusive) * @return the location */ static URI encodeLogFileLocation(UfsJournal journal, long start, long end) { String filename = String.format("0x%x-0x%x", start, end); URI location = URIUtils.appendPathOrDie(journal.getLogDir(), filename); return location; }