/* * Copyright (c) 2011 by Michael Berlin, Zuse Institute Berlin * * Licensed under the BSD License, see LICENSE file for details. * */ #ifndef CPP_INCLUDE_LIBXTREEMFS_CONTAINER_UUID_ITERATOR_H_ #define CPP_INCLUDE_LIBXTREEMFS_CONTAINER_UUID_ITERATOR_H_ #include #include #include #include #include #include "libxtreemfs/uuid_item.h" #include "libxtreemfs/uuid_iterator.h" #include "libxtreemfs/uuid_container.h" namespace xtreemfs { /** This class is a UUIDIterator that does not own its UUIDItems. Instead it * references a subset of UUIDItems stored in a UUIDContainer. The iterator * is initialized on construction and does not change during its lifetime. * The main use-case of this class is the OSD-addressing in a striped setup. * Such a setup can include multiple replicas, each with a different striping * configuration. So each object can have its individual list of OSDs over all * replicas. This list is needed in order to support redirection and automatic * fail-over. ContainerUUIDIterator stores this list. The UUIDContainer is * stored as a shared pointer at each UUIDIterator to ensure UUIDItems remain * valid as long as the UUIDIterator exists. */ class ContainerUUIDIterator : public UUIDIterator { public: /** This ctor initializes the iterator from a given UUIDContainer and a * vector of offsets. The offsets specify indices in the two-dimensional * container. */ ContainerUUIDIterator(boost::shared_ptr uuid_container, std::vector offsets) : uuid_container_(uuid_container) { uuid_container_->FillUUIDIterator(this, offsets); } virtual void SetCurrentUUID(const std::string& uuid); private: /** Reference to the container, this iterator and its UUIDs are derived from. * The container has to outlast every iterator and thus has to use a smart * pointer with reference counting. */ boost::shared_ptr uuid_container_; // UUIDContainer is a friend of this class friend void UUIDContainer::FillUUIDIterator( ContainerUUIDIterator* uuid_iterator, std::vector offsets); // the following is for testing template friend struct UUIDAdder; template friend UUIDIterator* CreateUUIDIterator(); /** Only for testing and UUIDContainer */ ContainerUUIDIterator() {} /** Only for testing and UUIDContainer */ virtual void Clear(); /** Add an existing UUIDItem. Ownership is NOT transferred. * It can only be called by UUIDContainer::GetUUIDIterator, hence the * friend-declaration above. */ void AddUUIDItem(UUIDItem* uuid); }; } // namespace xtreemfs #endif // CPP_INCLUDE_LIBXTREEMFS_CONTAINER_UUID_ITERATOR_H_