|
33 | 33 | import com.alibaba.fluss.metadata.ResolvedPartitionSpec;
|
34 | 34 | import com.alibaba.fluss.metadata.TableBucket;
|
35 | 35 | import com.alibaba.fluss.metadata.TablePath;
|
36 |
| -import com.alibaba.fluss.record.LogRecords; |
37 |
| -import com.alibaba.fluss.record.MemoryLogRecords; |
38 |
| -import com.alibaba.fluss.remote.RemoteLogFetchInfo; |
39 |
| -import com.alibaba.fluss.remote.RemoteLogSegment; |
40 |
| -import com.alibaba.fluss.rpc.entity.FetchLogResultForBucket; |
41 | 36 | import com.alibaba.fluss.rpc.messages.CreatePartitionRequest;
|
42 | 37 | import com.alibaba.fluss.rpc.messages.DropPartitionRequest;
|
43 | 38 | import com.alibaba.fluss.rpc.messages.GetFileSystemSecurityTokenResponse;
|
|
48 | 43 | import com.alibaba.fluss.rpc.messages.ListPartitionInfosResponse;
|
49 | 44 | import com.alibaba.fluss.rpc.messages.LookupRequest;
|
50 | 45 | import com.alibaba.fluss.rpc.messages.MetadataRequest;
|
51 |
| -import com.alibaba.fluss.rpc.messages.PbFetchLogRespForBucket; |
52 | 46 | import com.alibaba.fluss.rpc.messages.PbKeyValue;
|
53 | 47 | import com.alibaba.fluss.rpc.messages.PbKvSnapshot;
|
54 | 48 | import com.alibaba.fluss.rpc.messages.PbLakeSnapshotForBucket;
|
|
58 | 52 | import com.alibaba.fluss.rpc.messages.PbPrefixLookupReqForBucket;
|
59 | 53 | import com.alibaba.fluss.rpc.messages.PbProduceLogReqForBucket;
|
60 | 54 | import com.alibaba.fluss.rpc.messages.PbPutKvReqForBucket;
|
61 |
| -import com.alibaba.fluss.rpc.messages.PbRemoteLogFetchInfo; |
62 |
| -import com.alibaba.fluss.rpc.messages.PbRemoteLogSegment; |
63 | 55 | import com.alibaba.fluss.rpc.messages.PbRemotePathAndLocalFile;
|
64 | 56 | import com.alibaba.fluss.rpc.messages.PrefixLookupRequest;
|
65 | 57 | import com.alibaba.fluss.rpc.messages.ProduceLogRequest;
|
66 | 58 | import com.alibaba.fluss.rpc.messages.PutKvRequest;
|
67 |
| -import com.alibaba.fluss.rpc.protocol.ApiError; |
68 |
| -import com.alibaba.fluss.shaded.netty4.io.netty.buffer.ByteBuf; |
69 | 59 |
|
70 | 60 | import javax.annotation.Nullable;
|
71 | 61 |
|
72 |
| -import java.nio.ByteBuffer; |
73 | 62 | import java.util.ArrayList;
|
74 | 63 | import java.util.Arrays;
|
75 | 64 | import java.util.Collection;
|
76 | 65 | import java.util.HashMap;
|
77 | 66 | import java.util.List;
|
78 | 67 | import java.util.Map;
|
79 | 68 | import java.util.Set;
|
80 |
| -import java.util.UUID; |
81 | 69 | import java.util.stream.Collectors;
|
82 | 70 |
|
83 | 71 | import static com.alibaba.fluss.utils.Preconditions.checkState;
|
|
88 | 76 | */
|
89 | 77 | public class ClientRpcMessageUtils {
|
90 | 78 |
|
91 |
| - public static ByteBuffer toByteBuffer(ByteBuf buf) { |
92 |
| - if (buf.isDirect()) { |
93 |
| - return buf.nioBuffer(); |
94 |
| - } else if (buf.hasArray()) { |
95 |
| - int offset = buf.arrayOffset() + buf.readerIndex(); |
96 |
| - int length = buf.readableBytes(); |
97 |
| - return ByteBuffer.wrap(buf.array(), offset, length); |
98 |
| - } else { |
99 |
| - // fallback to deep copy |
100 |
| - byte[] bytes = new byte[buf.readableBytes()]; |
101 |
| - buf.getBytes(buf.readerIndex(), bytes); |
102 |
| - return ByteBuffer.wrap(bytes); |
103 |
| - } |
104 |
| - } |
105 |
| - |
106 | 79 | public static ProduceLogRequest makeProduceLogRequest(
|
107 | 80 | long tableId, int acks, int maxRequestTimeoutMs, List<WriteBatch> batches) {
|
108 | 81 | ProduceLogRequest request =
|
@@ -205,58 +178,6 @@ public static PrefixLookupRequest makePrefixLookupRequest(
|
205 | 178 | return request;
|
206 | 179 | }
|
207 | 180 |
|
208 |
| - public static FetchLogResultForBucket getFetchLogResultForBucket( |
209 |
| - TableBucket tb, TablePath tp, PbFetchLogRespForBucket respForBucket) { |
210 |
| - FetchLogResultForBucket fetchLogResultForBucket; |
211 |
| - if (respForBucket.hasErrorCode()) { |
212 |
| - fetchLogResultForBucket = |
213 |
| - new FetchLogResultForBucket(tb, ApiError.fromErrorMessage(respForBucket)); |
214 |
| - } else { |
215 |
| - if (respForBucket.hasRemoteLogFetchInfo()) { |
216 |
| - PbRemoteLogFetchInfo pbRlfInfo = respForBucket.getRemoteLogFetchInfo(); |
217 |
| - String partitionName = |
218 |
| - pbRlfInfo.hasPartitionName() ? pbRlfInfo.getPartitionName() : null; |
219 |
| - PhysicalTablePath physicalTablePath = PhysicalTablePath.of(tp, partitionName); |
220 |
| - List<RemoteLogSegment> remoteLogSegmentList = new ArrayList<>(); |
221 |
| - for (PbRemoteLogSegment pbRemoteLogSegment : pbRlfInfo.getRemoteLogSegmentsList()) { |
222 |
| - RemoteLogSegment remoteLogSegment = |
223 |
| - RemoteLogSegment.Builder.builder() |
224 |
| - .tableBucket(tb) |
225 |
| - .physicalTablePath(physicalTablePath) |
226 |
| - .remoteLogSegmentId( |
227 |
| - UUID.fromString( |
228 |
| - pbRemoteLogSegment.getRemoteLogSegmentId())) |
229 |
| - .remoteLogEndOffset(pbRemoteLogSegment.getRemoteLogEndOffset()) |
230 |
| - .remoteLogStartOffset( |
231 |
| - pbRemoteLogSegment.getRemoteLogStartOffset()) |
232 |
| - .segmentSizeInBytes(pbRemoteLogSegment.getSegmentSizeInBytes()) |
233 |
| - .maxTimestamp(-1L) // not use. |
234 |
| - .build(); |
235 |
| - remoteLogSegmentList.add(remoteLogSegment); |
236 |
| - } |
237 |
| - RemoteLogFetchInfo rlFetchInfo = |
238 |
| - new RemoteLogFetchInfo( |
239 |
| - pbRlfInfo.getRemoteLogTabletDir(), |
240 |
| - pbRlfInfo.hasPartitionName() ? pbRlfInfo.getPartitionName() : null, |
241 |
| - remoteLogSegmentList, |
242 |
| - pbRlfInfo.getFirstStartPos()); |
243 |
| - fetchLogResultForBucket = |
244 |
| - new FetchLogResultForBucket( |
245 |
| - tb, rlFetchInfo, respForBucket.getHighWatermark()); |
246 |
| - } else { |
247 |
| - ByteBuffer recordsBuffer = toByteBuffer(respForBucket.getRecordsSlice()); |
248 |
| - LogRecords records = |
249 |
| - respForBucket.hasRecords() |
250 |
| - ? MemoryLogRecords.pointToByteBuffer(recordsBuffer) |
251 |
| - : MemoryLogRecords.EMPTY; |
252 |
| - fetchLogResultForBucket = |
253 |
| - new FetchLogResultForBucket(tb, records, respForBucket.getHighWatermark()); |
254 |
| - } |
255 |
| - } |
256 |
| - |
257 |
| - return fetchLogResultForBucket; |
258 |
| - } |
259 |
| - |
260 | 181 | public static KvSnapshots toKvSnapshots(GetLatestKvSnapshotsResponse response) {
|
261 | 182 | long tableId = response.getTableId();
|
262 | 183 | Long partitionId = response.hasPartitionId() ? response.getPartitionId() : null;
|
|
0 commit comments