-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[ML] Make ManagedLedger storage configurable #9397
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /** | ||
| * 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.pulsar.broker.storage; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.bookkeeper.client.BookKeeper; | ||
| import org.apache.bookkeeper.mledger.ManagedLedgerFactory; | ||
| import org.apache.bookkeeper.stats.StatsProvider; | ||
| import org.apache.pulsar.broker.BookKeeperClientFactory; | ||
| import org.apache.pulsar.broker.ServiceConfiguration; | ||
| import org.apache.pulsar.common.classification.InterfaceAudience.Private; | ||
| import org.apache.pulsar.common.classification.InterfaceStability.Unstable; | ||
| import org.apache.zookeeper.ZooKeeper; | ||
|
|
||
| /** | ||
| * Storage to access {@link org.apache.bookkeeper.mledger.ManagedLedger}s. | ||
| */ | ||
| @Private | ||
| @Unstable | ||
| public interface ManagedLedgerStorage extends AutoCloseable { | ||
|
|
||
| /** | ||
| * Initialize the managed ledger storage. | ||
| * | ||
| * @param conf service config | ||
| * @param zkClient zk client | ||
| * @param bookkeperProvider bookkeeper provider | ||
| * @throws Exception | ||
| */ | ||
| void initialize(ServiceConfiguration conf, | ||
| ZooKeeper zkClient, | ||
| BookKeeperClientFactory bookkeperProvider) throws Exception; | ||
|
|
||
| /** | ||
| * Return the factory to create {@link ManagedLedgerFactory}. | ||
| * | ||
| * @return the factory to create {@link ManagedLedgerFactory}. | ||
| */ | ||
| ManagedLedgerFactory getManagedLedgerFactory(); | ||
|
|
||
| /** | ||
| * Return the stats provider to expose the stats of the storage implementation. | ||
| * | ||
| * @return the stats provider. | ||
| */ | ||
| StatsProvider getStatsProvider(); | ||
|
|
||
| /** | ||
| * Return the default bookkeeper client. | ||
| * | ||
| * @return the default bookkeeper client. | ||
| */ | ||
| BookKeeper getBookKeeperClient(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to support different storage, why the interface contains the bookkeeper client related method, seems this should be handled in the implementation?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably this interface should be org.apache.bookkeeper.client.api.Bookkeeper (the new BK API) if we want to look forward for the future.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codelipenghui This is the first attempt to provide an interface. It is a bit difficult to hide everything at this moment. Hence I marked the interface as private and unstable. So we can iterate changes over this interface.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eolivelli see reasons above.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure @sijie
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need approval from @codelipenghui and @315157973 |
||
|
|
||
| /** | ||
| * Close the storage. | ||
| * | ||
| * @throws IOException | ||
| */ | ||
| void close() throws IOException; | ||
|
|
||
| /** | ||
| * Initialize the {@link ManagedLedgerStorage} from the provided resources. | ||
| * | ||
| * @param conf service config | ||
| * @param zkClient zookeeper client | ||
| * @param bkProvider bookkeeper client provider | ||
| * @return the initialized managed ledger storage. | ||
| */ | ||
| static ManagedLedgerStorage create(ServiceConfiguration conf, | ||
| ZooKeeper zkClient, | ||
| BookKeeperClientFactory bkProvider) throws Exception { | ||
| final Class<?> storageClass = Class.forName(conf.getManagedLedgerStorageClassName()); | ||
| final ManagedLedgerStorage storage = (ManagedLedgerStorage) storageClass.newInstance(); | ||
| storage.initialize(conf, zkClient, bkProvider); | ||
| return storage; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * 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. | ||
| */ | ||
| /** | ||
| * The storage layer for Apache Pulsar. | ||
| */ | ||
| package org.apache.pulsar.broker.storage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we wrap an object or abstract a client API, which has nothing to do with the storage medium, would it be better?
If it is abstract, we don’t have to use zk or bk.
In the future, we will increase the storage type, only need to modify this object, and no need to modify the interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@315157973 see my comment in #9397 (comment)