ShardManager
public class ShardManager
The ShardManager
class is responsible for managing a collection of Shard
objects.
It provides functionality for storing, retrieving, and managing shards, as well as handling
file-related configurations and compression methods.
- Properties:
shards
: A dictionary mappingString
keys toShard
objects, representing the managed shards.baseURL
: The base URL where shard files are stored.compressionMethod
: The method used for compressing shard data.fileProtectionType
: The file protection type applied to shard files.autoMergeTask
: An optional asynchronous task for automatically merging shards.
-
Undocumented
Declaration
Swift
public let fileProtectionType: FileProtectionType
-
Initializes a new instance of
ShardManager
.Declaration
Swift
public init( baseURL: URL, compressionMethod: CompressionMethod = .none, fileProtectionType: FileProtectionType = .none )
Parameters
baseURL
The base URL where the shard files will be stored.
compressionMethod
The method used for compressing shard data. Defaults to
.none
.fileProtectionType
The file protection level applied to the shard files. Defaults to
.none
. -
createShard(withID:
Asynchronous) Creates a new shard with the specified identifier.
Throws
An error if the shard creation fails.Note
This method is asynchronous and must be called withawait
.Declaration
Swift
public func createShard(withID id: String) async throws -> Shard
Parameters
id
A unique identifier for the shard to be created.
Return Value
The newly created
Shard
instance. -
getOrCreateShard(id:
Asynchronous) Retrieves an existing shard with the specified identifier or creates a new one if it does not exist.
Throws
An error if the shard cannot be retrieved or created.Note
This method is asynchronous and must be awaited.Declaration
Swift
public func getOrCreateShard(id: String) async throws -> Shard
Parameters
id
A unique identifier for the shard.
Return Value
The shard associated with the given identifier.
-
Retrieves a shard by its unique identifier.
Throws
An error if the shard cannot be found or if there is an issue retrieving it.Declaration
Swift
public func getShard(byID id: String) throws -> Shard
Parameters
id
The unique identifier of the shard to retrieve.
Return Value
The
Shard
instance corresponding to the provided identifier. -
Retrieves metadata information for all shards.
Declaration
Swift
public func allShardInfo() -> [ShardMetadataInfo]
Return Value
An array of
ShardMetadataInfo
objects containing metadata details for all shards managed by theShardManager
. -
Loads all shards into memory.
This method is responsible for initializing and loading the shards that are managed by the
ShardManager
. It ensures that the shards are properly prepared for use within the database system.Declaration
Swift
public func loadShards()
-
cleanupEmptyShards()
AsynchronousCleans up and removes any empty shards from the database.
This method asynchronously iterates through the shards managed by the
ShardManager
and deletes any shards that are determined to be empty.Throws
An error if the cleanup process encounters any issues.Declaration
Swift
public func cleanupEmptyShards() async throws
-
Removes all shards managed by the
ShardManager
.This method deletes all shard files or data associated with the
ShardManager
. Use this method with caution as it will result in the loss of all stored data.Throws
An error if the operation fails, such as due to file system issues or insufficient permissions.Declaration
Swift
public func removeAllShards() throws