Package io.pravega.shared
Class NameUtils
- java.lang.Object
-
- io.pravega.shared.NameUtils
-
public final class NameUtils extends java.lang.ObjectUtility methods for StreamSegment Names.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringINTERNAL_NAME_PREFIXstatic java.lang.StringINTERNAL_SCOPE_NAMEstatic intMAX_GIVEN_NAME_SIZESize of the name that can be specified by user.static intMAX_NAME_SIZESize of the overall name as permitted by the host.static intMAX_PREFIX_OR_SUFFIX_SIZESize of the prefix or suffix included with the user stream name.static java.lang.StringREADER_GROUP_STREAM_PREFIX
-
Constructor Summary
Constructors Constructor Description NameUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longcomputeSegmentId(int segmentNumber, int epoch)Method to compute 64 bit segment id which takes segment number and epoch and composes it as `msb = epoch` `lsb = segmentNumber`.static java.lang.StringextractPrimaryStreamSegmentName(java.lang.String streamSegmentName)Attempts to extract the primary part of stream segment name before the epoch delimiter.static java.util.List<java.lang.String>extractScopedNameTokens(java.lang.String scopedName)Returns a list representing the components of a scoped Stream/Key-Value Table name.static java.util.List<java.lang.String>extractSegmentTokens(java.lang.String qualifiedName)Method to extract different parts of stream segment name.static java.util.List<java.lang.String>extractTableSegmentTokens(java.lang.String qualifiedName)Method to extract tokens that were used to compose fully qualified table segment name using method getQualifiedTableName.static java.lang.StringgetAttributeSegmentName(java.lang.String segmentName)Gets the name of the meta-Segment mapped to the given Segment Name that is responsible with storing extended attributes.static intgetEpoch(long segmentId)Method to extract epoch from given segment id.static intgetEpoch(java.util.UUID txnId)Method to extract epoch from given transaction id.static java.lang.StringgetHeaderSegmentName(java.lang.String segmentName)Gets the name of the meta-Segment mapped to the given Segment Name that is responsible with storing its Rollover information.static java.lang.StringgetInternalNameForStream(java.lang.String streamName)Construct an internal representation of stream name.static java.lang.StringgetMARK_PREFIX()Prefix for identifying system created mark segments for storing watermarks.static java.lang.StringgetMarkStreamForStream(java.lang.String stream)static java.lang.StringgetMetadataSegmentName(int containerId)Gets the name of the Segment that is used to store the Container's Segment Metadata.static java.lang.StringgetParentStreamSegmentName(java.lang.String transactionName)Attempts to extract the name of the Parent StreamSegment for the given Transaction StreamSegment.static java.lang.StringgetQualifiedStreamSegmentName(java.lang.String scope, java.lang.String streamName, long segmentId)Method to generate Fully Qualified StreamSegmentName using scope, stream and segment id.static java.lang.StringgetQualifiedTableName(java.lang.String scope, java.lang.String... tokens)Method to generate Fully Qualified table name using scope, and other tokens to be used to compose the table name.static java.lang.StringgetQualifiedTableSegmentName(java.lang.String scope, java.lang.String kvTableName, long segmentId)Method to generate Fully Qualified TableSegmentName using scope, stream and segment id.static java.lang.StringgetScopedKeyValueTableName(java.lang.String scope, java.lang.String streamName)Compose and return scoped Key-Value Table name.static java.lang.StringgetScopedReaderGroupName(java.lang.String scope, java.lang.String rgName)Compose and return scoped ReaderGroup name.static java.lang.StringgetScopedStreamName(java.lang.String scope, java.lang.String streamName)Compose and return scoped stream name.static java.lang.StringgetSegmentChunkName(java.lang.String segmentName, long offset)Gets the name of the SegmentChunk for the given Segment and Offset.static java.lang.StringgetSegmentChunkName(java.lang.String segmentName, long epoch, long offset)Gets the name of the SegmentChunk for the given segment, epoch and offset.static java.lang.StringgetSegmentNameFromHeader(java.lang.String headerSegmentName)Gets the name of the Segment name from its Header Segment Name.static intgetSegmentNumber(long segmentId)Method to extract segmentNumber from given segment id.static java.lang.StringgetSegmentReadIndexBlockName(java.lang.String segmentName, long offset)Gets the name of the read index block entry for the given segment and offset.static java.lang.StringgetStorageMetadataSegmentName(int containerId)Gets the name of the Segment that is used to store the Container's Segment Metadata.static java.lang.StringgetStreamForReaderGroup(java.lang.String groupNameName)Construct a stream name which will internally be used by the readergroup implementation.static java.lang.StringgetSystemJournalFileName(int containerId, long epoch, long currentFileIndex)Gets file name of SystemJournal for given container instance.static java.lang.StringgetSystemJournalSnapshotFileName(int containerId, long epoch, long currentSnapshotIndex)Gets file name of SystemJournal snapshot for given container instance.static java.lang.StringgetTransactionNameFromId(java.lang.String parentStreamSegmentName, java.util.UUID transactionId)Returns the transaction name for a TransactionStreamSegment based on the name of the current Parent StreamSegment, and the transactionId.static booleanisAttributeSegment(java.lang.String segmentName)Checks whether the given name is an Attribute Segment or not.static booleanisHeaderSegment(java.lang.String segmentName)Checks whether given name is a Header Segment.static booleanisTableSegment(java.lang.String qualifiedName)Method to check if given segment name is a table name generated using getQualifiedTableName.static booleanisTransactionSegment(java.lang.String streamSegmentName)Checks if the given stream segment name is formatted for a Transaction Segment or regular segment.static java.lang.String[]segmentTags(java.lang.String qualifiedSegmentName)Generate segment tags (string array) on the input fully qualified segment name to be associated with a metric.static java.lang.String[]segmentTags(java.lang.String qualifiedSegmentName, java.lang.String writerId)Generate segment tags (string array) on the input fully qualified segment name and writer id to be associated with a metric.static java.lang.StringvalidateReaderGroupName(java.lang.String name)Validates a reader group name.static java.lang.StringvalidateReaderId(java.lang.String readerId)Validates a readerId.static java.lang.StringvalidateScopeName(java.lang.String name)Validates a scope name.static java.lang.StringvalidateStreamName(java.lang.String name)Validates an internal stream name.static java.lang.StringvalidateUserKeyValueTableName(java.lang.String name)Validates a user-created Key-Value Table name.static java.lang.StringvalidateUserScopeName(java.lang.String name)Validates a user created scope name.static java.lang.StringvalidateUserStreamName(java.lang.String name)Validates a user created stream name.static java.lang.StringvalidateWriterId(java.lang.String writerId)Validates a writerId.static java.lang.String[]writerTags(java.lang.String writerId)Generate writer tags (string array) based on the writerId.
-
-
-
Field Detail
-
INTERNAL_NAME_PREFIX
public static final java.lang.String INTERNAL_NAME_PREFIX
- See Also:
- Constant Field Values
-
INTERNAL_SCOPE_NAME
public static final java.lang.String INTERNAL_SCOPE_NAME
- See Also:
- Constant Field Values
-
READER_GROUP_STREAM_PREFIX
public static final java.lang.String READER_GROUP_STREAM_PREFIX
- See Also:
- Constant Field Values
-
MAX_PREFIX_OR_SUFFIX_SIZE
public static final int MAX_PREFIX_OR_SUFFIX_SIZE
Size of the prefix or suffix included with the user stream name.- See Also:
- Constant Field Values
-
MAX_NAME_SIZE
public static final int MAX_NAME_SIZE
Size of the overall name as permitted by the host.- See Also:
- Constant Field Values
-
MAX_GIVEN_NAME_SIZE
public static final int MAX_GIVEN_NAME_SIZE
Size of the name that can be specified by user.- See Also:
- Constant Field Values
-
-
Method Detail
-
getTransactionNameFromId
public static java.lang.String getTransactionNameFromId(java.lang.String parentStreamSegmentName, java.util.UUID transactionId)Returns the transaction name for a TransactionStreamSegment based on the name of the current Parent StreamSegment, and the transactionId.- Parameters:
parentStreamSegmentName- The name of the Parent StreamSegment for this transaction.transactionId- The unique Id for the transaction.- Returns:
- The name of the Transaction StreamSegmentId.
-
getParentStreamSegmentName
public static java.lang.String getParentStreamSegmentName(java.lang.String transactionName)
Attempts to extract the name of the Parent StreamSegment for the given Transaction StreamSegment. This method returns a valid value only if the Transaction StreamSegmentName was generated using the generateTransactionStreamSegmentName method.- Parameters:
transactionName- The name of the Transaction StreamSegment to extract the name of the Parent StreamSegment.- Returns:
- The name of the Parent StreamSegment, or null if not a valid StreamSegment.
-
isTransactionSegment
public static boolean isTransactionSegment(java.lang.String streamSegmentName)
Checks if the given stream segment name is formatted for a Transaction Segment or regular segment.- Parameters:
streamSegmentName- The name of the StreamSegment to check for transaction delimiter.- Returns:
- true if stream segment name contains transaction delimiter, false otherwise.
-
extractPrimaryStreamSegmentName
public static java.lang.String extractPrimaryStreamSegmentName(java.lang.String streamSegmentName)
Attempts to extract the primary part of stream segment name before the epoch delimiter. This method returns a valid value only if the StreamSegmentName was generated using the getQualifiedStreamSegmentName method.- Parameters:
streamSegmentName- The name of the StreamSegment to extract the name of the Primary StreamSegment name.- Returns:
- The primary part of StreamSegment.
-
isAttributeSegment
public static boolean isAttributeSegment(java.lang.String segmentName)
Checks whether the given name is an Attribute Segment or not.- Parameters:
segmentName- The name of the segment.- Returns:
- True if the segment is an attribute Segment, false otherwise.
-
getAttributeSegmentName
public static java.lang.String getAttributeSegmentName(java.lang.String segmentName)
Gets the name of the meta-Segment mapped to the given Segment Name that is responsible with storing extended attributes.- Parameters:
segmentName- The name of the Segment to get the Attribute segment name for.- Returns:
- The result.
-
getHeaderSegmentName
public static java.lang.String getHeaderSegmentName(java.lang.String segmentName)
Gets the name of the meta-Segment mapped to the given Segment Name that is responsible with storing its Rollover information. Existence of this file should also indicate that a Segment with this file has a rollover policy in place.- Parameters:
segmentName- The name of the Segment to get the Header segment name for.- Returns:
- The result.
-
isHeaderSegment
public static boolean isHeaderSegment(java.lang.String segmentName)
Checks whether given name is a Header Segment.- Parameters:
segmentName- The name of the segment.- Returns:
- true if the name is Header Segment. False otherwise
-
getSegmentNameFromHeader
public static java.lang.String getSegmentNameFromHeader(java.lang.String headerSegmentName)
Gets the name of the Segment name from its Header Segment Name.- Parameters:
headerSegmentName- The name of the Header Segment.- Returns:
- The Segment Name.
-
getSegmentChunkName
public static java.lang.String getSegmentChunkName(java.lang.String segmentName, long offset)Gets the name of the SegmentChunk for the given Segment and Offset.- Parameters:
segmentName- The name of the Segment to get the SegmentChunk name for.offset- The starting offset of the SegmentChunk.- Returns:
- The SegmentChunk name.
-
getSegmentChunkName
public static java.lang.String getSegmentChunkName(java.lang.String segmentName, long epoch, long offset)Gets the name of the SegmentChunk for the given segment, epoch and offset.- Parameters:
segmentName- The name of the Segment to get the SegmentChunk name for.epoch- The epoch of the container.offset- The starting offset of the SegmentChunk.- Returns:
- formatted chunk name.
-
getSegmentReadIndexBlockName
public static java.lang.String getSegmentReadIndexBlockName(java.lang.String segmentName, long offset)Gets the name of the read index block entry for the given segment and offset.- Parameters:
segmentName- The name of the Segment.offset- The starting offset of the block.- Returns:
- formatted read index block entry name.
-
getMetadataSegmentName
public static java.lang.String getMetadataSegmentName(int containerId)
Gets the name of the Segment that is used to store the Container's Segment Metadata. There is one such Segment per container.- Parameters:
containerId- The Id of the Container.- Returns:
- The Metadata Segment name.
-
getStorageMetadataSegmentName
public static java.lang.String getStorageMetadataSegmentName(int containerId)
Gets the name of the Segment that is used to store the Container's Segment Metadata. There is one such Segment per container.- Parameters:
containerId- The Id of the Container.- Returns:
- The Metadata Segment name.
-
getSystemJournalFileName
public static java.lang.String getSystemJournalFileName(int containerId, long epoch, long currentFileIndex)Gets file name of SystemJournal for given container instance.- Parameters:
containerId- The Id of the Container.epoch- Epoch of the container instance.currentFileIndex- Current index for journal file.- Returns:
- File name of SystemJournal for given container instance
-
getSystemJournalSnapshotFileName
public static java.lang.String getSystemJournalSnapshotFileName(int containerId, long epoch, long currentSnapshotIndex)Gets file name of SystemJournal snapshot for given container instance.- Parameters:
containerId- The Id of the Container.epoch- Epoch of the container instance.currentSnapshotIndex- Current index for journal file.- Returns:
- File name of SystemJournal for given container instance
-
computeSegmentId
public static long computeSegmentId(int segmentNumber, int epoch)Method to compute 64 bit segment id which takes segment number and epoch and composes it as `msb = epoch` `lsb = segmentNumber`. Primary id identifies the segment container mapping and primary + secondary uniquely identifies a segment within a stream.- Parameters:
segmentNumber- segment number.epoch- epoch in which segment was created.- Returns:
- segment id which is composed using segment number and epoch.
-
getSegmentNumber
public static int getSegmentNumber(long segmentId)
Method to extract segmentNumber from given segment id. Segment number is encoded in 32 msb of segment id- Parameters:
segmentId- segment id.- Returns:
- segment number by extracting it from segment id.
-
getEpoch
public static int getEpoch(long segmentId)
Method to extract epoch from given segment id. Epoch is encoded in 32 lsb of the segment id.- Parameters:
segmentId- segment id.- Returns:
- epoch by extracting it from segment id.
-
getEpoch
public static int getEpoch(java.util.UUID txnId)
Method to extract epoch from given transaction id.- Parameters:
txnId- Unique id of the transaction.- Returns:
- epoch by extracting it the transaction id.
-
getScopedStreamName
public static java.lang.String getScopedStreamName(java.lang.String scope, java.lang.String streamName)Compose and return scoped stream name.- Parameters:
scope- scope to be used in ScopedStream name.streamName- stream name to be used in ScopedStream name.- Returns:
- scoped stream name.
-
getScopedKeyValueTableName
public static java.lang.String getScopedKeyValueTableName(java.lang.String scope, java.lang.String streamName)Compose and return scoped Key-Value Table name.- Parameters:
scope- scope to be used in scoped Key-Value Table name.streamName- Key-Value Table name to be used in Scoped Key-Value Table name.- Returns:
- scoped Key-Value Table name.
-
getScopedReaderGroupName
public static java.lang.String getScopedReaderGroupName(java.lang.String scope, java.lang.String rgName)Compose and return scoped ReaderGroup name.- Parameters:
scope- scope to be used in ScopedReaderGroup name.rgName- ReaderGroup name to be used in ScopedReaderGroup name.- Returns:
- scoped stream name.
-
getQualifiedTableSegmentName
public static java.lang.String getQualifiedTableSegmentName(java.lang.String scope, java.lang.String kvTableName, long segmentId)Method to generate Fully Qualified TableSegmentName using scope, stream and segment id.- Parameters:
scope- scope to be used in the ScopedTableSegment namekvTableName- kvTable name to be used in ScopedTableSegment name.segmentId- segment id to be used in ScopedStreamSegment name.- Returns:
- fully qualified TableSegmentName for a TableSegment that is part of the KeyValueTable.
-
extractScopedNameTokens
public static java.util.List<java.lang.String> extractScopedNameTokens(java.lang.String scopedName)
Returns a list representing the components of a scoped Stream/Key-Value Table name.- Parameters:
scopedName- The scoped name.- Returns:
- A list containing the components. If the scoped name was properly formatted, this list should have two elements: element index 0 has the scope name and element index 1 has the stream name.
- Throws:
java.lang.IllegalStateException- If 'scopedName' is not in the form 'scope/name`.
-
getQualifiedStreamSegmentName
public static java.lang.String getQualifiedStreamSegmentName(java.lang.String scope, java.lang.String streamName, long segmentId)Method to generate Fully Qualified StreamSegmentName using scope, stream and segment id.- Parameters:
scope- scope to be used in the ScopedStreamSegment namestreamName- stream name to be used in ScopedStreamSegment name.segmentId- segment id to be used in ScopedStreamSegment name.- Returns:
- fully qualified StreamSegmentName.
-
extractSegmentTokens
public static java.util.List<java.lang.String> extractSegmentTokens(java.lang.String qualifiedName)
Method to extract different parts of stream segment name. The tokens extracted are in following order scope, stream name and segment id. If its a transational segment, the transaction id is ignored. This function works even when scope is not set.- Parameters:
qualifiedName- StreamSegment's qualified name.- Returns:
- tokens capturing different components of stream segment name. Note: segmentId is extracted and sent back as a String
-
getQualifiedTableName
public static java.lang.String getQualifiedTableName(java.lang.String scope, java.lang.String... tokens)Method to generate Fully Qualified table name using scope, and other tokens to be used to compose the table name. The composed name has following format: <scope>/_tables/<tokens[0]>/<tokens[1]>...- Parameters:
scope- scope in which table segment to createtokens- tokens used for composing table segment name- Returns:
- Fully qualified table segment name composed of supplied tokens.
-
extractTableSegmentTokens
public static java.util.List<java.lang.String> extractTableSegmentTokens(java.lang.String qualifiedName)
Method to extract tokens that were used to compose fully qualified table segment name using method getQualifiedTableName. The first token in the returned list corresponds to scope. Remainder tokens correspond to tokens used to compose tableName.- Parameters:
qualifiedName- fully qualified table name- Returns:
- tokens capturing different components of table segment name. First element in the list represents scope
-
isTableSegment
public static boolean isTableSegment(java.lang.String qualifiedName)
Method to check if given segment name is a table name generated using getQualifiedTableName.- Parameters:
qualifiedName- qualified table name- Returns:
- true if the name is generated using getQualifiedTableName. False otherwise
-
segmentTags
public static java.lang.String[] segmentTags(java.lang.String qualifiedSegmentName)
Generate segment tags (string array) on the input fully qualified segment name to be associated with a metric.- Parameters:
qualifiedSegmentName- Fully qualified segment name.- Returns:
- String array as segment tag of metric.
-
segmentTags
public static java.lang.String[] segmentTags(java.lang.String qualifiedSegmentName, java.lang.String writerId)Generate segment tags (string array) on the input fully qualified segment name and writer id to be associated with a metric.- Parameters:
qualifiedSegmentName- Fully qualified segment name.writerId- The writer id.- Returns:
- String arrays as a segment tag of metric.
-
writerTags
public static java.lang.String[] writerTags(java.lang.String writerId)
Generate writer tags (string array) based on the writerId.- Parameters:
writerId- Writer id.- Returns:
- String array as writer tag of metric.
-
getInternalNameForStream
public static java.lang.String getInternalNameForStream(java.lang.String streamName)
Construct an internal representation of stream name. This is required to distinguish between user created and pravega internally created streams.- Parameters:
streamName- The stream name for which we need to construct an internal name.- Returns:
- The stream name which has to be used internally in the pravega system.
-
getStreamForReaderGroup
public static java.lang.String getStreamForReaderGroup(java.lang.String groupNameName)
Construct a stream name which will internally be used by the readergroup implementation.- Parameters:
groupNameName- The readergroup name for which we need to construct an internal stream name.- Returns:
- The stream name which has to be used internally by the reader group implementation.
-
validateUserStreamName
public static java.lang.String validateUserStreamName(java.lang.String name)
Validates a user created stream name.- Parameters:
name- User supplied stream name to validate.- Returns:
- The name in the case is valid.
-
validateUserKeyValueTableName
public static java.lang.String validateUserKeyValueTableName(java.lang.String name)
Validates a user-created Key-Value Table name.- Parameters:
name- User supplied Key-Value Table name to validate.- Returns:
- The name, if valid.
-
validateStreamName
public static java.lang.String validateStreamName(java.lang.String name)
Validates an internal stream name.- Parameters:
name- Stream name to validate.- Returns:
- The name in the case is valid.
-
validateUserScopeName
public static java.lang.String validateUserScopeName(java.lang.String name)
Validates a user created scope name.- Parameters:
name- Scope name to validate.- Returns:
- The name in the case is valid.
-
validateScopeName
public static java.lang.String validateScopeName(java.lang.String name)
Validates a scope name.- Parameters:
name- Scope name to validate.- Returns:
- The name in the case is valid.
-
validateReaderGroupName
public static java.lang.String validateReaderGroupName(java.lang.String name)
Validates a reader group name.- Parameters:
name- Reader group name to validate.- Returns:
- The name in the case is valid.
-
validateReaderId
public static java.lang.String validateReaderId(java.lang.String readerId)
Validates a readerId.- Parameters:
readerId- ReaderId to validate.- Returns:
- The name in the case is valid.
-
validateWriterId
public static java.lang.String validateWriterId(java.lang.String writerId)
Validates a writerId.- Parameters:
writerId- ReaderId to validate.- Returns:
- The name in the case is valid.
-
getMarkStreamForStream
public static java.lang.String getMarkStreamForStream(java.lang.String stream)
-
getMARK_PREFIX
public static java.lang.String getMARK_PREFIX()
Prefix for identifying system created mark segments for storing watermarks.
-
-