ctubbsii commented on code in PR #2976: URL: https://github.com/apache/accumulo/pull/2976#discussion_r982690259
########## core/src/main/java/org/apache/accumulo/fate/ReadOnlyStore.java: ########## @@ -1,124 +0,0 @@ -/* - * 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 - * - * https://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.accumulo.fate; - -import static java.util.Objects.requireNonNull; - -import java.io.Serializable; -import java.util.EnumSet; -import java.util.List; - -/** - * This store decorates a TStore to make sure it can not be modified. - * - * Unlike relying directly on the ReadOnlyTStore interface, this class will not allow subsequent - * users to cast back to a mutable TStore successfully. - */ -public class ReadOnlyStore<T> implements ReadOnlyTStore<T> { - - private final ZooStore<T> store; - - /** - * @param store - * may not be null - */ - public ReadOnlyStore(ZooStore<T> store) { - requireNonNull(store); - this.store = store; - } - - @Override - public long reserve() { - return store.reserve(); - } - - @Override - public void reserve(long tid) { - store.reserve(tid); - } - - @Override - public void unreserve(long tid, long deferTime) { - store.unreserve(tid, deferTime); - } - - /** - * Decorates a Repo to make sure it is treated as a ReadOnlyRepo. - * - * Similar to ReadOnlyStore, won't allow subsequent user to cast a ReadOnlyRepo back to a mutable - * Repo. - */ - protected static class ReadOnlyRepoWrapper<X> implements ReadOnlyRepo<X> { - private final Repo<X> repo; - - /** - * @param repo - * may not be null - */ - public ReadOnlyRepoWrapper(Repo<X> repo) { - requireNonNull(repo); - this.repo = repo; - } - - @Override - public long isReady(long tid, X environment) throws Exception { - return repo.isReady(tid, environment); - } - - @Override - public String getName() { - return repo.getName(); - } - } - - @Override - public ReadOnlyRepo<T> top(long tid) { - return new ReadOnlyRepoWrapper<>(store.top(tid)); - } Review Comment: I'm not sure what protections we're losing by removing this interface... but we could easily fix any NPE errors as a result of attempting to wrap `store.top(tid)` when it returns null by doing: ```java public ReadOnlyRepo<T> top(long tid) { var top = store.top(tid); return top == null ? null : new ReadOnlyRepoWrapper<>(top); } ``` It might be safer to do this than to remove this interface entirely. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
