Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileCopy based bootstrap] GetMetadata Api #2991

Merged
merged 23 commits into from
Feb 20, 2025
Merged

Conversation

DevenAhluwalia
Copy link
Contributor

@DevenAhluwalia DevenAhluwalia commented Jan 22, 2025

Ticket

BUG=AMBRY-13007

Summary

Adds GetMetadata Api required for bootstrap replication improvements using file copy based protocol.

Testing Done

Test logs :-

2025/01/24 07:51:22.080 INFO [AmbryServer] [main] [ambry-server] [] Dw: Request: FileCopyGetMetaDataRequest[PartitionId=146, HostName=hostName]
2025/01/24 07:51:22.569 INFO [AmbryServer] [main] [ambry-server] [] Dw: Response: FileCopyGetMetaDataResponse[NumberOfLogfiles=2, logInfoList[LogInfo[FileName=0_62, FileSizeInBytes=4001180, IndexFiles=[FileInfo[FileName=0_62_18_index, FileSizeInBytes=364]], BloomFilters=[FileInfo[FileName=0_62_18_bloom, FileSizeInBytes=50024]]], LogInfo[FileName=24_0, FileSizeInBytes=1349928533, IndexFiles=[FileInfo[FileName=24_0_18_index, FileSizeInBytes=36572]]]]]

@DevenAhluwalia DevenAhluwalia self-assigned this Jan 22, 2025
@DevenAhluwalia DevenAhluwalia marked this pull request as ready for review February 8, 2025 16:48
return sb.toString();
}

@Override
public void accept(RequestVisitor visitor) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we using this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in a generic infra defined in RequestMetricsUpdater

This powers some common metrics like qps for a particular request type defined here.

public List<LogInfo> getLogInfos() {
return logInfos;
return Collections.unmodifiableList(logInfos);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this to be unmodifiableList?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures that the list cannot be modified from outside the class and helps in maintaining the immutability of the list and prevents accidental or intentional modifications.
Checked the demo master branch and this works well there too with FileCopyHandler caller code.

null, null, totalTimeSpent));
}

private List<LogInfo> convertStoreToProtocolLogInfo(List<com.github.ambry.store.LogInfo> logSegments) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use one LogInfo class so we don't need to do this conversion. Maybe we can put the LogInfo to ambry-api package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request handler for this api is in ambry-server module.
Protocol class is required to have network stream SerDe (alongwith readFrom, prepareBuffer etc) same as any other protocol request/response classes in ambry-protocol module.
BlobStore/FileStore need their Pojos (LogInfo, FileInfo) in ambry-store module as it doesn't have a dependency on Protocol module (and vice-versa)

Eventually, we need similar constructs in ambry-store and ambry-protocol modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is same in some other apis where Store and Protocol class conversion is happening.
fe, check this BatchDelete Api code

List<BlobDeleteStatus> blobDeleteStatuses = new ArrayList<>();
for (StoreKey storeKey : batchDeletePartitionRequestInfo.getBlobIds()){
    blobDeleteStatuses.add(new BlobDeleteStatus((BlobId)storeKey, ServerErrorCode.Unknown_Error));
}

BlobDeleteStatus is a protocol class while StoreKey is a Store class and we are converting from Store to Protocol class. Just that in my case, I have named both classes same (LogInfo) and created a private converter util.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put these classes under ambry-api modules. Just like FindToken. This way, you don't need two identical classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty for pointing this out @justinlin-linkedin
PTAL at the latest diff.

Changelog :-
Fixes the consolidation of pojos. Protocol/pojos no longer exist.
New interfaces are in common place api-module and Store, Protocol classes implement it.

* @param buf The output stream.
*/
public void writeTo(@Nonnull ByteBuf buf){
Objects.requireNonNull(buf, "buf should not be null");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @nonnull annotation will already be doing this check. We should remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nonnull works as a static warning. Shows up as red line in the calling code if null is passed but it doesn't give a compilation error. I tried the same. From tests, I was able to pass null. Hence, I added a requireNonNull check.


RequestMetricsUpdater metricsUpdater = new RequestMetricsUpdater(
requestQueueTime, processingTime, 0, 0, false);
if (null != fileCopyGetMetaDataRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fileCopyGetMetaDataRequest != null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
public class FileInfo {
/**
* Name of the file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove redundant comments

* @param includeActiveLogSegment
* @return
*/
List<LogInfo> getLogSegmentMetadataFiles(boolean includeActiveLogSegment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a default access modifier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default access modifier would be public in an interface.
the default keyword would mean that a default impl exists for this method (which btw, doesn't).

Can you pls elaborate what could be the default access modifier here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes , i meant public modifier

Comment on lines 188 to 210
StringBuilder sb = new StringBuilder();
sb.append("LogInfo[");
sb.append("FileName=").append(fileName).append(", FileSizeInBytes=").append(fileSizeInBytes).append(",");
for(FileInfo fileInfo : indexFiles) {
sb.append(fileInfo.toString());
sb.append("FileName=").append(fileName).append(", FileSizeInBytes=").append(fileSizeInBytes);

if(!indexFiles.isEmpty()) {
sb.append(", IndexFiles=[");
for (FileInfo fileInfo : indexFiles) {
sb.append(fileInfo.toString());
}
sb.append("]");
if(!bloomFilters.isEmpty()) {
sb.append(", ");
}
}
for(FileInfo fileInfo: bloomFilters){
sb.append(fileInfo.toString());
if(!bloomFilters.isEmpty()){
sb.append(" BloomFilters=[");
for(FileInfo fileInfo: bloomFilters){
sb.append(fileInfo.toString());
}
sb.append("]");
}
sb.append("]");
return sb.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not this?

{
  return "LogInfo{" +
      "fileName='" + fileName + '\'' +
      ", fileSizeInBytes=" + fileSizeInBytes +
      ", indexFiles=" + indexFiles +
      ", bloomFilters=" + bloomFilters +
      '}';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely remember this.
iirc, it should have worked but It was not recursively printing indexFiles and bloomFilters.

Indexfiles and bloomfiles are of type List<FileInfo> and List wont get strigified as is. So, I needed to iterate over these values and then delegate to indexfile/bloomfile-toString()

@DevenAhluwalia DevenAhluwalia merged commit d9d1f5b into master Feb 20, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants