Class RackawareEnsemblePlacementPolicyImpl

    • Field Detail

      • LOG

        static final org.slf4j.Logger LOG
      • maxWeightMultiple

        int maxWeightMultiple
      • minNumRacksPerWriteQuorum

        protected int minNumRacksPerWriteQuorum
      • enforceMinNumRacksPerWriteQuorum

        protected boolean enforceMinNumRacksPerWriteQuorum
      • ignoreLocalNodeInPlacementPolicy

        protected boolean ignoreLocalNodeInPlacementPolicy
      • REPP_RANDOM_READ_REORDERING

        public static final java.lang.String REPP_RANDOM_READ_REORDERING
        See Also:
        Constant Field Values
      • RACKNAME_DISTANCE_FROM_LEAVES

        static final int RACKNAME_DISTANCE_FROM_LEAVES
        See Also:
        Constant Field Values
      • timer

        protected io.netty.util.HashedWheelTimer timer
      • slowBookies

        protected com.google.common.cache.Cache<org.apache.bookkeeper.net.BookieId,​java.lang.Long> slowBookies
      • localNode

        protected org.apache.bookkeeper.net.BookieNode localNode
      • reorderReadsRandom

        protected boolean reorderReadsRandom
      • enforceDurability

        protected boolean enforceDurability
      • stabilizePeriodSeconds

        protected int stabilizePeriodSeconds
      • reorderThresholdPendingRequests

        protected int reorderThresholdPendingRequests
      • readReorderedCounter

        @StatsDoc(name="READ_REQUESTS_REORDERED",
                  help="The distribution of number of bookies reordered on each read request")
        protected OpStatsLogger readReorderedCounter
      • failedToResolveNetworkLocationCounter

        @StatsDoc(name="FAILED_TO_RESOLVE_NETWORK_LOCATION_TOTAL",
                  help="Counter for number of times DNSResolverDecorator failed to resolve Network Location")
        protected Counter failedToResolveNetworkLocationCounter
      • numWritableBookiesInDefaultRack

        @StatsDoc(name="NUM_WRITABLE_BOOKIES_IN_DEFAULT_RACK",
                  help="Gauge for the number of writable Bookies in default rack")
        protected Gauge<java.lang.Integer> numWritableBookiesInDefaultRack
    • Constructor Detail

      • RackawareEnsemblePlacementPolicyImpl

        RackawareEnsemblePlacementPolicyImpl()
      • RackawareEnsemblePlacementPolicyImpl

        RackawareEnsemblePlacementPolicyImpl​(boolean enforceDurability)
    • Method Detail

      • initialize

        protected RackawareEnsemblePlacementPolicyImpl initialize​(org.apache.bookkeeper.net.DNSToSwitchMapping dnsResolver,
                                                                  io.netty.util.HashedWheelTimer timer,
                                                                  boolean reorderReadsRandom,
                                                                  int stabilizePeriodSeconds,
                                                                  int reorderThresholdPendingRequests,
                                                                  boolean isWeighted,
                                                                  int maxWeightMultiple,
                                                                  int minNumRacksPerWriteQuorum,
                                                                  boolean enforceMinNumRacksPerWriteQuorum,
                                                                  boolean ignoreLocalNodeInPlacementPolicy,
                                                                  StatsLogger statsLogger,
                                                                  org.apache.bookkeeper.proto.BookieAddressResolver bookieAddressResolver)
        Initialize the policy.
        Parameters:
        dnsResolver - the object used to resolve addresses to their network address
        Returns:
        initialized ensemble placement policy
      • getDefaultRack

        public java.lang.String getDefaultRack()
      • initialize

        public RackawareEnsemblePlacementPolicyImpl initialize​(ClientConfiguration conf,
                                                               java.util.Optional<org.apache.bookkeeper.net.DNSToSwitchMapping> optionalDnsResolver,
                                                               io.netty.util.HashedWheelTimer timer,
                                                               FeatureProvider featureProvider,
                                                               StatsLogger statsLogger,
                                                               org.apache.bookkeeper.proto.BookieAddressResolver bookieAddressResolver)
        Description copied from interface: EnsemblePlacementPolicy
        Initialize the policy.
        Parameters:
        conf - client configuration
        optionalDnsResolver - dns resolver
        timer - timer
        featureProvider - feature provider
        statsLogger - stats logger
      • uninitalize

        public void uninitalize()
        Description copied from interface: EnsemblePlacementPolicy
        Uninitialize the policy.
      • addDefaultRackBookiesIfMinNumRacksIsEnforced

        protected java.util.Set<org.apache.bookkeeper.net.BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced​(java.util.Set<org.apache.bookkeeper.net.BookieId> excludeBookies)
      • replaceBookie

        public EnsemblePlacementPolicy.PlacementResult<org.apache.bookkeeper.net.BookieId> replaceBookie​(int ensembleSize,
                                                                                                         int writeQuorumSize,
                                                                                                         int ackQuorumSize,
                                                                                                         java.util.Map<java.lang.String,​byte[]> customMetadata,
                                                                                                         java.util.List<org.apache.bookkeeper.net.BookieId> currentEnsemble,
                                                                                                         org.apache.bookkeeper.net.BookieId bookieToReplace,
                                                                                                         java.util.Set<org.apache.bookkeeper.net.BookieId> excludeBookies)
                                                                                                  throws BKException.BKNotEnoughBookiesException
        Description copied from interface: EnsemblePlacementPolicy
        Choose a new bookie to replace bookieToReplace. If no bookie available in the cluster, BKException.BKNotEnoughBookiesException is thrown.

        If 'enforceMinNumRacksPerWriteQuorum' config is enabled then the bookies belonging to default faultzone (rack) will be excluded while selecting bookies.

        Parameters:
        ensembleSize - the value of ensembleSize
        writeQuorumSize - the value of writeQuorumSize
        ackQuorumSize - the value of ackQuorumSize (added since 4.5)
        customMetadata - the value of customMetadata. it is the same user defined metadata that user provides in BookKeeper.createLedger(int, int, int, BookKeeper.DigestType, byte[])
        currentEnsemble - the value of currentEnsemble
        bookieToReplace - bookie to replace
        excludeBookies - bookies that should not be considered as candidate.
        Returns:
        a placement result containing the new bookie address.
        Throws:
        BKException.BKNotEnoughBookiesException
      • registerSlowBookie

        public void registerSlowBookie​(org.apache.bookkeeper.net.BookieId bookieSocketAddress,
                                       long entryId)
        Description copied from interface: EnsemblePlacementPolicy
        Register a bookie as slow so that it is tried after available and read-only bookies.
        Parameters:
        bookieSocketAddress - Address of bookie host
        entryId - Entry ID that caused a speculative timeout on the bookie.
      • reorderReadSequenceWithRegion

        DistributionSchedule.WriteSet reorderReadSequenceWithRegion​(java.util.List<org.apache.bookkeeper.net.BookieId> ensemble,
                                                                    DistributionSchedule.WriteSet writeSet,
                                                                    java.util.Map<java.lang.Integer,​java.lang.String> writeSetWithRegion,
                                                                    BookiesHealthInfo bookiesHealthInfo,
                                                                    boolean regionAware,
                                                                    java.lang.String myRegion,
                                                                    int remoteNodeInReorderSequence)
        This function orders the read sequence with a given region. For region-unaware policies (e.g. RackAware), we pass in false for regionAware and an empty myRegion. When this happens, any remote list will stay empty. The ordering is as follows (the R* at the beginning of each list item is only present for region aware policies). 1. available (local) bookies 2. R* a remote bookie (based on remoteNodeInReorderSequence 3. R* remaining (local) bookies 4. R* remaining remote bookies 5. read only bookies 6. slow bookies 7. unavailable bookies
        Parameters:
        ensemble - ensemble of bookies
        writeSet - write set
        writeSetWithRegion - write set with region information
        bookiesHealthInfo - heuristics about health of boookies
        regionAware - whether or not a region-aware policy is used
        myRegion - current region of policy
        remoteNodeInReorderSequence - number of local bookies to try before trying a remote bookie
        Returns:
        ordering of bookies to send read to
      • isEnsembleAdheringToPlacementPolicy

        public EnsemblePlacementPolicy.PlacementPolicyAdherence isEnsembleAdheringToPlacementPolicy​(java.util.List<org.apache.bookkeeper.net.BookieId> ensembleList,
                                                                                                    int writeQuorumSize,
                                                                                                    int ackQuorumSize)
        Description copied from interface: EnsemblePlacementPolicy
        returns AdherenceLevel if the Ensemble is strictly/softly/fails adhering to placement policy, like in the case of RackawareEnsemblePlacementPolicy, bookies in the writeset are from 'minNumRacksPerWriteQuorum' number of racks. And in the case of RegionawareEnsemblePlacementPolicy, check for minimumRegionsForDurability, reppRegionsToWrite, rack distribution within a region and other parameters of RegionAwareEnsemblePlacementPolicy. In ZoneAwareEnsemblePlacementPolicy if bookies in the writeset are from 'desiredNumOfZones' then it is considered as MEETS_STRICT if they are from 'minNumOfZones' then it is considered as MEETS_SOFT otherwise considered as FAIL.
        Parameters:
        ensembleList - list of BookieId of bookies in the ensemble
        writeQuorumSize - writeQuorumSize of the ensemble
        ackQuorumSize - ackQuorumSize of the ensemble
        Returns:
      • areAckedBookiesAdheringToPlacementPolicy

        public boolean areAckedBookiesAdheringToPlacementPolicy​(java.util.Set<org.apache.bookkeeper.net.BookieId> ackedBookies,
                                                                int writeQuorumSize,
                                                                int ackQuorumSize)
        Description copied from interface: EnsemblePlacementPolicy
        Returns true if the bookies that have acknowledged a write adhere to the minimum fault domains as defined in the placement policy in use. Ex: In the case of RackawareEnsemblePlacementPolicy, bookies belong to at least 'minNumRacksPerWriteQuorum' number of racks.
        Parameters:
        ackedBookies - list of BookieId of bookies that have acknowledged a write.
        writeQuorumSize - writeQuorumSize of the ensemble
        ackQuorumSize - ackQuorumSize of the ensemble
        Returns:
      • replaceToAdherePlacementPolicy

        public EnsemblePlacementPolicy.PlacementResult<java.util.List<org.apache.bookkeeper.net.BookieId>> replaceToAdherePlacementPolicy​(int ensembleSize,
                                                                                                                                          int writeQuorumSize,
                                                                                                                                          int ackQuorumSize,
                                                                                                                                          java.util.Set<org.apache.bookkeeper.net.BookieId> excludeBookies,
                                                                                                                                          java.util.List<org.apache.bookkeeper.net.BookieId> currentEnsemble)
        Description copied from interface: EnsemblePlacementPolicy
        Returns placement result. If the currentEnsemble is not adhering placement policy, returns new ensemble that adheres placement policy. It should be implemented so as to minify the number of bookies replaced.
        Parameters:
        ensembleSize - ensemble size
        writeQuorumSize - writeQuorumSize of the ensemble
        ackQuorumSize - ackQuorumSize of the ensemble
        excludeBookies - bookies that should not be considered as targets
        currentEnsemble - current ensemble
        Returns:
        a placement result