Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.client;
import io.netty.util.HashedWheelTimer;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.feature.FeatureProvider;
import org.apache.bookkeeper.net.BookieId;
import org.apache.bookkeeper.net.BookieNode;
import org.apache.bookkeeper.net.DNSToSwitchMapping;
import org.apache.bookkeeper.proto.BookieAddressResolver;
import org.apache.bookkeeper.stats.StatsLogger;
/**
* A placement policy implementation use zone information for placing ensembles.
*
* @see EnsemblePlacementPolicy
*/
public class ZoneawareEnsemblePlacementPolicy extends ZoneawareEnsemblePlacementPolicyImpl
implements ITopologyAwareEnsemblePlacementPolicy {
ZoneawareEnsemblePlacementPolicyImpl slave = null;
public ZoneawareEnsemblePlacementPolicy() {
super();
}
@Override
public EnsemblePlacementPolicy initialize(ClientConfiguration conf,
Optional optionalDnsResolver, HashedWheelTimer timer,
FeatureProvider featureProvider,
StatsLogger statsLogger, BookieAddressResolver bookieAddressResolver) {
if (conf.getNetworkTopologyStabilizePeriodSeconds() > 0) {
ClientConfiguration confClone = new ClientConfiguration(conf);
confClone.setNetworkTopologyStabilizePeriodSeconds(0);
super.initialize(confClone, optionalDnsResolver, timer, featureProvider,
statsLogger, bookieAddressResolver);
slave = new ZoneawareEnsemblePlacementPolicyImpl();
slave.initialize(conf, optionalDnsResolver, timer, featureProvider, statsLogger, bookieAddressResolver);
} else {
super.initialize(conf, optionalDnsResolver, timer, featureProvider, statsLogger, bookieAddressResolver);
slave = null;
}
return this;
}
@Override
public void uninitalize() {
super.uninitalize();
if (null != slave) {
slave.uninitalize();
}
}
@Override
public Set onClusterChanged(Set writableBookies,
Set readOnlyBookies) {
Set deadBookies = super.onClusterChanged(writableBookies, readOnlyBookies);
if (null != slave) {
deadBookies = slave.onClusterChanged(writableBookies, readOnlyBookies);
}
return deadBookies;
}
@Override
public PlacementResult> newEnsemble(int ensembleSize, int writeQuorumSize,
int ackQuorumSize, Map customMetadata, Set excludeBookies)
throws BKException.BKNotEnoughBookiesException {
try {
return super.newEnsemble(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, excludeBookies);
} catch (BKException.BKNotEnoughBookiesException bnebe) {
if (slave == null) {
throw bnebe;
} else {
return slave.newEnsemble(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, excludeBookies);
}
}
}
@Override
public PlacementResult replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize,
Map customMetadata, List currentEnsemble,
BookieId bookieToReplace, Set excludeBookies)
throws BKException.BKNotEnoughBookiesException {
try {
return super.replaceBookie(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata,
currentEnsemble, bookieToReplace, excludeBookies);
} catch (BKException.BKNotEnoughBookiesException bnebe) {
if (slave == null) {
throw bnebe;
} else {
return slave.replaceBookie(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata,
currentEnsemble, bookieToReplace, excludeBookies);
}
}
}
@Override
public void handleBookiesThatLeft(Set leftBookies) {
super.handleBookiesThatLeft(leftBookies);
if (null != slave) {
slave.handleBookiesThatLeft(leftBookies);
}
}
@Override
public void handleBookiesThatJoined(Set joinedBookies) {
super.handleBookiesThatJoined(joinedBookies);
if (null != slave) {
slave.handleBookiesThatJoined(joinedBookies);
}
}
}