//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2018 ArangoDB GmbH, Cologne, Germany /// /// Licensed 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. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Tobias Gödderz //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGOD_CLUSTER_CLUSTER_REPAIR_DISTRIBUTE_SHARDS_LIKE_H #define ARANGOD_CLUSTER_CLUSTER_REPAIR_DISTRIBUTE_SHARDS_LIKE_H #include #include #include #include #include #include "Agency/AgencyComm.h" #include "ClusterInfo.h" #include "ClusterRepairOperations.h" #include "ResultT.h" namespace arangodb { namespace velocypack { class Slice; template class Buffer; } // namespace velocypack namespace cluster_repairs { using DBServers = std::vector; using VPackBufferPtr = std::shared_ptr>; template std::ostream& operator<<(std::ostream& stream, std::array array) { stream << "std::array<" << typeid(T).name() << "> { "; std::for_each(array.begin(), array.end(), [&stream](T const& val) { stream << val << ", "; }); stream << "}"; return stream; } inline std::ostream& operator<<(std::ostream& stream, VPackBufferPtr const& vpack) { return stream << "std::shared_ptr { " << velocypack::Slice(vpack->data()).toJson() << " " << "}"; } struct Collection { DatabaseID database; std::string name; CollectionID id; uint64_t replicationFactor; bool deleted; bool isSmart; std::optional distributeShardsLike; std::optional repairingDistributeShardsLike; std::map shardsById; std::string inline fullName() const { return this->database + "/" + this->name; } Collection() = delete; // constructor with named parameters Collection(tagged_argument database_, tagged_argument collectionId_, tagged_argument collectionName_, tagged_argument replicationFactor_, tagged_argument deleted_, tagged_argument isSmart_, tagged_argument> distributeShardsLike_, tagged_argument> repairingDistributeShardsLike_, tagged_argument> shardsById_); }; class DistributeShardsLikeRepairer { public: ResultT>>> static repairDistributeShardsLike( velocypack::Slice const& planCollections, velocypack::Slice const& supervisionHealth); private: std::map static readShards(velocypack::Slice const& shards); DBServers static readDatabases(velocypack::Slice const& planDbServers); ResultT> static readCollections( velocypack::Slice const& collectionsByDatabase); std::optional static findFreeServer(DBServers const& availableDbServers, DBServers const& shardDbServers); std::vector> static findCollectionsToFix( std::map collections); DBServers static serverSetDifference(DBServers setA, DBServers setB); DBServers static serverSetSymmetricDifference(DBServers setA, DBServers setB); MoveShardOperation static createMoveShardOperation(struct Collection& collection, ShardID const& shardId, ServerID const& fromServerId, ServerID const& toServerId, bool isLeader); // "proto collection" always means the collection referred to in the // "distributeShardsLike" attribute of "collection" ResultT> static fixLeader(DBServers const& availableDbServers, struct Collection& collection, struct Collection const& proto, ShardID const& shardId, ShardID const& protoShardId); ResultT> static fixShard(DBServers const& availableDbServers, struct Collection& collection, struct Collection const& proto, ShardID const& shardId, ShardID const& protoShardId); ResultT> static createFixServerOrderOperation( struct Collection& collection, struct Collection const& proto, ShardID const& shardId, ShardID const& protoShardId); ResultT static createBeginRepairsOperation( struct Collection& collection, struct Collection const& proto); std::vector static createShardVector( std::map const& shardsById, std::map const& protoShardsById); ResultT static createFinishRepairsOperation( struct Collection& collection, struct Collection const& proto); ResultT> static fixAllShardsOfCollection( struct Collection& collection, struct Collection const& proto, DBServers const& availableDbServers); }; } // namespace cluster_repairs } // namespace arangodb #endif // ARANGOD_CLUSTER_CLUSTER_REPAIR_DISTRIBUTE_SHARDS_LIKE_H