-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FileCopy based bootstrap] GetDataChunk Api (#3013)
* Api2 WIP * Api2 WIP * Api2 WIP * Api2 WIP * Api2 WIP * Fixing broken test (#3020) * Fixing broken test * Adding tests * PR comments * PR comments
- Loading branch information
1 parent
36aefbb
commit d14df63
Showing
17 changed files
with
923 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
ambry-api/src/main/java/com/github/ambry/store/PartitionFileStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2025 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* 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.store; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* Represents a store that contains log segments. | ||
* Provides methods to get a ByteBuffer for a file chunk and to put a chunk to a file. | ||
* Also provides methods to persist and read metadata to/from a partition. | ||
*/ | ||
public interface PartitionFileStore { | ||
/** | ||
* Get a ByteBuffer for a file chunk. | ||
* @param fileName the name of the requested file. This could be a log segment, index segment or bloom filter. | ||
* @param offset the start offset of the requested chunk. | ||
* @param size the size of the requested chunk in bytes. | ||
* @return a StoreFileChunk representing the chunk stream of the file requested. | ||
* @throws StoreException | ||
*/ | ||
StoreFileChunk getByteBufferForFileChunk(String fileName, long offset, long size) throws StoreException; | ||
|
||
/** | ||
* Put a chunk to a file. | ||
* @param outputFilePath the path of the file to put the chunk to. | ||
* @param dataInputStream the chunk stream of the file to put. | ||
* @throws IOException | ||
*/ | ||
void putChunkToFile(String outputFilePath, DataInputStream dataInputStream) throws IOException; | ||
|
||
/** | ||
* Persist metadata for a partition. This metadata contains information about log segments, associated index segments and bloom filters. | ||
* @param logInfoList the list of LogInfo objects to persist. | ||
* @throws IOException | ||
*/ | ||
void persistMetaDataToFile(List<LogInfo> logInfoList) throws IOException; | ||
|
||
/** | ||
* Read metadata from a partition. This metadata contains information about log segments, associated index segments and bloom filters. | ||
* @return | ||
* @throws IOException | ||
*/ | ||
List<LogInfo> readMetaDataFromFile() throws IOException; | ||
} |
86 changes: 86 additions & 0 deletions
86
ambry-api/src/main/java/com/github/ambry/store/StoreFileChunk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright 2025 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* 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.store; | ||
|
||
import com.github.ambry.utils.ByteBufferInputStream; | ||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.Objects; | ||
|
||
|
||
/** | ||
* Represents a file chunk that exists in the store | ||
*/ | ||
public class StoreFileChunk { | ||
/** | ||
* The chunk stream of the file requested. | ||
*/ | ||
private final DataInputStream stream; | ||
|
||
/** | ||
* The size of the chunk in bytes. | ||
*/ | ||
private final long chunkLength; | ||
|
||
/** | ||
* Constructor to create a StoreFileChunk | ||
* @param stream the chunk stream of the file requested | ||
* @param chunkLength the size of the chunk in bytes | ||
*/ | ||
public StoreFileChunk(DataInputStream stream, long chunkLength) { | ||
Objects.requireNonNull(stream, "DataInputStream cannot be null"); | ||
|
||
this.stream = stream; | ||
this.chunkLength = chunkLength; | ||
} | ||
|
||
/** | ||
* Create a StoreFileChunk from a ByteBuffer | ||
* @param buf the ByteBuffer to create the StoreFileChunk from | ||
* @return StoreFileChunk representing the chunk stream of the file requested | ||
*/ | ||
public static StoreFileChunk from(ByteBuffer buf) { | ||
Objects.requireNonNull(buf, "ByteBuffer cannot be null"); | ||
return new StoreFileChunk( | ||
new DataInputStream(new ByteBufferInputStream(buf)), buf.remaining()); | ||
} | ||
|
||
/** | ||
* Convert the chunk stream to a ByteBuffer | ||
* @return ByteBuffer representing the chunk stream of the file requested | ||
* @throws IOException | ||
*/ | ||
public ByteBuffer toBuffer() throws IOException { | ||
byte[] buf = new byte[(int) chunkLength]; | ||
stream.readFully(buf); | ||
return ByteBuffer.wrap(buf); | ||
} | ||
|
||
/** | ||
* Get the chunk stream of the file requested | ||
* @return DataInputStream representing the chunk stream of the file requested | ||
*/ | ||
public DataInputStream getStream() { | ||
return stream; | ||
} | ||
|
||
/** | ||
* Get the size of the chunk in bytes | ||
* @return the size of the chunk in bytes | ||
*/ | ||
public long getChunkLength() { | ||
return chunkLength; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.