Skip to content

Commit

Permalink
Added comments for implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jai Balani committed Feb 13, 2025
1 parent 003663b commit 25cdc87
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,53 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/


package com.github.ambry.clustermap;

public class FileStoreException extends RuntimeException{
/**
* Custom exception class for FileStore-related errors.
* Extends RuntimeException to allow unchecked exception handling.
* Includes specific error codes for different failure scenarios.
*/
public class FileStoreException extends RuntimeException {

// Ensures proper serialization across JVM versions
private static final long serialVersionUID = 1L;

// Stores the specific error code associated with this exception
private final FileStoreErrorCode error;

/**
* Creates a new FileStoreException with a message and error code.
*
* @param s The error message describing what went wrong
* @param error The specific error code categorizing the failure
*/
public FileStoreException(String s, FileStoreErrorCode error) {
super(s);
this.error = error;
}

/**
* Creates a new FileStoreException with a message, error code, and cause.
*
* @param s The error message describing what went wrong
* @param error The specific error code categorizing the failure
* @param throwable The underlying cause of this exception
*/
public FileStoreException(String s, FileStoreErrorCode error, Throwable throwable) {
super(s, throwable);
this.error = error;
}

public enum FileStoreErrorCode{
/**
* Enumeration of possible FileStore error codes.
* Each code represents a specific category of failure.
*/
public enum FileStoreErrorCode {
/**
* Indicates that the FileStore service is not in running state
* when an operation was attempted.
*/
FileStoreRunningFailure
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,74 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/


package com.github.ambry.config;

/**
* Configuration parameters for file copy operations in Ambry.
* This class manages settings related to:
* - Parallel processing
* - Thread management
* - Timeouts
* - Data flushing
* - Metadata file naming
*/
public class FileCopyConfig {

/**
* Number of partitions that can be hydrated in parallel per disk.
* Higher values increase parallelism but also resource usage.
*/
public static final String PARALLEL_PARTITION_HYDRATION_COUNT_PER_DISK = "parallel.partition.hydration.count.per.disk";
@Config(PARALLEL_PARTITION_HYDRATION_COUNT_PER_DISK)
public final int parallelPartitionHydrationCountPerDisk;

/**
* Number of threads dedicated to file copy operations.
* Controls the level of concurrent file transfers.
*/
public static final String NUMBER_OF_FILE_COPY_THREADS = "number.of.file.copy.threads";
@Config(NUMBER_OF_FILE_COPY_THREADS)
public final int numberOfFileCopyThreads;

/**
* Timeout duration for file chunk operations in minutes.
* After this duration, incomplete chunk operations are considered failed.
*/
public static final String FILE_CHUNK_TIMEOUT_IN_MINUTES = "file.chunk.timeout.in.minutes";
@Config(FILE_CHUNK_TIMEOUT_IN_MINUTES)
public final long fileChunkTimeoutInMins;

/**
* The frequency at which the data gets flushed to disk
* The frequency at which data gets flushed to disk in megabytes.
* Lower values increase durability but may impact performance.
* Default: 1000MB
*/
public static final String STORE_DATA_FLUSH_INTERVAL_IN_MBS = "store.data.flush.interval.In.MBs";
@Config(STORE_DATA_FLUSH_INTERVAL_IN_MBS)
@Default("1000")
public final long storeDataFlushIntervalInMbs;

/**
* Name of the metadata file used for file copy operations.
* This file stores information about sealed logs and their associated metadata.
* Default: "sealed_logs_metadata_file"
*/
public static final String FILE_COPY_META_DATA_FILE_NAME = "file.copy.meta.data.file.name";
@Config(FILE_COPY_META_DATA_FILE_NAME)
@Default("sealed_logs_metadata_file")
public final String fileCopyMetaDataFileName;

/**
* Creates a new FileCopyConfig with the provided properties.
*
* @param verifiableProperties Properties containing configuration values
* If a property is not specified, default values are used:
* - parallelPartitionHydrationCountPerDisk: 1
* - numberOfFileCopyThreads: 4
* - fileChunkTimeoutInMins: 5
* - storeDataFlushIntervalInMbs: 1000
* - fileCopyMetaDataFileName: "sealed_logs_metadata_file"
*/
public FileCopyConfig(VerifiableProperties verifiableProperties) {
fileCopyMetaDataFileName = verifiableProperties.getString(FILE_COPY_META_DATA_FILE_NAME, "sealed_logs_metadata_file");
parallelPartitionHydrationCountPerDisk = verifiableProperties.getInt(PARALLEL_PARTITION_HYDRATION_COUNT_PER_DISK, 1);
Expand Down
32 changes: 32 additions & 0 deletions ambry-api/src/main/java/com/github/ambry/store/FileInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,54 @@

package com.github.ambry.store;

/**
* Represents metadata about a file in the Ambry storage system.
* Contains basic file information like name and size.
* Used for tracking file details during copy operations and metadata management.
*/
public class FileInfo {
// Name of the file, including any path components
private String fileName;

// Size of the file in bytes
// Marked final as size shouldn't change after creation
private final long fileSize;

/**
* Creates a new FileInfo instance.
*
* @param fileName Name or path of the file
* @param fileSize Size of the file in bytes
*/
public FileInfo(String fileName, Long fileSize) {
this.fileName = fileName;
this.fileSize = fileSize;
}

/**
* Gets the name of the file.
*
* @return The file name or path
*/
public String getFileName() {
return fileName;
}

/**
* Gets the size of the file in bytes.
*
* @return The file size
*/
public Long getFileSize() {
return fileSize;
}

/**
* Returns a string representation of the FileInfo object.
* Useful for logging and debugging.
*
* @return String containing file name and size
*/
@Override
public String toString() {
return "FileInfo{" +
Expand Down
59 changes: 57 additions & 2 deletions ambry-api/src/main/java/com/github/ambry/store/LogInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,102 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/


package com.github.ambry.store;

import java.util.List;


/**
* Represents information about a log segment and its associated metadata files.
* Contains details about:
* - The sealed log segment
* - Associated index segments
* - Bloom filters for efficient lookups
*/
public class LogInfo {
// The sealed log segment containing the actual data
FileInfo sealedSegment;

// List of index segments associated with this log
// Each index segment provides lookup capabilities for a portion of the log
List<FileInfo> indexSegments;

// List of bloom filters for efficient key lookups
// Each bloom filter corresponds to an index segment
List<FileInfo> bloomFilters;

/**
* Creates a new LogInfo instance with the specified components.
*
* @param sealedSegment The sealed log segment file information
* @param indexSegments List of index segment file information
* @param bloomFilters List of bloom filter file information
*/
public LogInfo(FileInfo sealedSegment, List<FileInfo> indexSegments, List<FileInfo> bloomFilters) {
this.sealedSegment = sealedSegment;
this.indexSegments = indexSegments;
this.bloomFilters = bloomFilters;
}

/**
* Gets the sealed log segment information.
*
* @return FileInfo for the sealed log segment
*/
public FileInfo getSealedSegment() {
return sealedSegment;
}

/**
* Sets the sealed log segment information.
*
* @param sealedSegments New sealed segment information
*/
public void setSealedSegments(FileInfo sealedSegments) {
this.sealedSegment = sealedSegments;
}

/**
* Gets the list of index segment information.
*
* @return List of FileInfo objects for index segments
*/
public List<FileInfo> getIndexSegments() {
return indexSegments;
}

/**
* Sets the list of index segment information.
*
* @param indexSegments New list of index segment information
*/
public void setIndexSegments(List<FileInfo> indexSegments) {
this.indexSegments = indexSegments;
}

/**
* Gets the list of bloom filter information.
*
* @return List of FileInfo objects for bloom filters
*/
public List<FileInfo> getBloomFilters() {
return bloomFilters;
}

/**
* Sets the list of bloom filter information.
*
* @param bloomFilters New list of bloom filter information
*/
public void setBloomFilters(List<FileInfo> bloomFilters) {
this.bloomFilters = bloomFilters;
}

/**
* Returns a string representation of the LogInfo object.
* Useful for logging and debugging.
*
* @return String containing details of sealed segment, index segments, and bloom filters
*/
@Override
public String toString() {
return "LogInfo{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2025 LinkedIn Corp. All rights reserved.
* Copyright 2024 LinkedIn Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -11,7 +11,6 @@
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/

package com.github.ambry.protocol;

import com.github.ambry.utils.Utils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.github.ambry.config.ClusterMapConfig;
import com.github.ambry.config.ConnectionPoolConfig;
import com.github.ambry.config.DiskManagerConfig;
import com.github.ambry.config.FileCopyConfig;
import com.github.ambry.config.Http2ClientConfig;
import com.github.ambry.config.NettyConfig;
import com.github.ambry.config.NetworkConfig;
Expand Down
Loading

0 comments on commit 25cdc87

Please sign in to comment.