Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tiered storage] store driver name and driver specific metadata in o…
…riginal ledger metadata (#2398) ### Motivation 1) Currently the location of an offloaded ledger isn't stored in the original ledger metadata. That means if configuration is changed or modified by mistake. We might potentially cause data loss. 2) The location of an offloaded ledger is needed by Pulsar SQL. so it is very inconvinient to have the location information stored in a configuration and the approach is also problematic. ### Changes Store `driverName` and driver-specific metadata (e.g. bucket name, region name, endpoint) in the original ledger metadata. Change ManagedLedgerImpl to use the driver-specific metadata to read the offloaded ledger. If the driver-specific metadata is missed, it will fall back to use the configuration. ### Tests This change doesn't change the behavior. Existing unit tests and integration tests already covered the logic. ### NOTES Currently the driver name in metadata is not used. We need to use driver name to load different offloader driver after #2393 is implemented
- Loading branch information
Showing
11 changed files
with
419 additions
and
84 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
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
91 changes: 91 additions & 0 deletions
91
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/offload/OffloadUtils.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,91 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.bookkeeper.mledger.offload; | ||
|
||
import com.google.common.collect.Maps; | ||
import java.util.Map; | ||
import org.apache.bookkeeper.mledger.proto.MLDataFormats.KeyValue; | ||
import org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedLedgerInfo.LedgerInfo; | ||
import org.apache.bookkeeper.mledger.proto.MLDataFormats.OffloadContext; | ||
import org.apache.bookkeeper.mledger.proto.MLDataFormats.OffloadDriverMetadata; | ||
|
||
public final class OffloadUtils { | ||
|
||
private OffloadUtils() {} | ||
|
||
public static Map<String, String> getOffloadDriverMetadata(LedgerInfo ledgerInfo) { | ||
Map<String, String> metadata = Maps.newHashMap(); | ||
if (ledgerInfo.hasOffloadContext()) { | ||
OffloadContext ctx = ledgerInfo.getOffloadContext(); | ||
if (ctx.hasDriverMetadata()) { | ||
OffloadDriverMetadata driverMetadata = ctx.getDriverMetadata(); | ||
if (driverMetadata.getPropertiesCount() > 0) { | ||
driverMetadata.getPropertiesList().forEach(kv -> metadata.put(kv.getKey(), kv.getValue())); | ||
} | ||
} | ||
} | ||
return metadata; | ||
} | ||
|
||
public static Map<String, String> getOffloadDriverMetadata(LedgerInfo ledgerInfo, | ||
Map<String, String> defaultOffloadDriverMetadata) { | ||
if (ledgerInfo.hasOffloadContext()) { | ||
OffloadContext ctx = ledgerInfo.getOffloadContext(); | ||
if (ctx.hasDriverMetadata()) { | ||
OffloadDriverMetadata driverMetadata = ctx.getDriverMetadata(); | ||
if (driverMetadata.getPropertiesCount() > 0) { | ||
Map<String, String> metadata = Maps.newHashMap(); | ||
driverMetadata.getPropertiesList().forEach(kv -> metadata.put(kv.getKey(), kv.getValue())); | ||
return metadata; | ||
} | ||
} | ||
} | ||
return defaultOffloadDriverMetadata; | ||
} | ||
|
||
public static String getOffloadDriverName(LedgerInfo ledgerInfo, String defaultDriverName) { | ||
if (ledgerInfo.hasOffloadContext()) { | ||
OffloadContext ctx = ledgerInfo.getOffloadContext(); | ||
if (ctx.hasDriverMetadata()) { | ||
OffloadDriverMetadata driverMetadata = ctx.getDriverMetadata(); | ||
if (driverMetadata.hasName()) { | ||
return driverMetadata.getName(); | ||
} | ||
} | ||
} | ||
return defaultDriverName; | ||
} | ||
|
||
public static void setOffloadDriverMetadata(LedgerInfo.Builder infoBuilder, | ||
String driverName, | ||
Map<String, String> offloadDriverMetadata) { | ||
infoBuilder.getOffloadContextBuilder() | ||
.getDriverMetadataBuilder() | ||
.setName(driverName); | ||
offloadDriverMetadata.forEach((k, v) -> { | ||
infoBuilder.getOffloadContextBuilder() | ||
.getDriverMetadataBuilder() | ||
.addProperties(KeyValue.newBuilder() | ||
.setKey(k) | ||
.setValue(v) | ||
.build()); | ||
}); | ||
} | ||
|
||
} |
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.