Commit b8ab2d5b authored by David Auer's avatar David Auer
Browse files

Reformat random slicing files

parent 8124e99d
Loading
Loading
Loading
Loading
+181 −170
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ namespace VDRIVE {
 */
class Disk {
public:

    /**
     * Create a new instance from the data in the given XML Element.
     *
@@ -66,14 +65,16 @@ namespace VDRIVE {
     *
     * @return ID of the disk. Has to be unique all over this library.
     */
        int64_t getId() const;
    int64_t
    getId() const;

    /**
     * Set the ID of the disk. Has to be unique all over this library.
     *
     * @param id ID of the disk. Has to be unique all over this library.
     */
        void setId(int64_t id);
    void
    setId(int64_t id);

    /**
     * Get the Capacity of the Disk in bytes. (This can also be in any
@@ -83,7 +84,8 @@ namespace VDRIVE {
     *         other scale, but has to be same for ExtentSize of
     *         Distributor)
     */
        int64_t getCapacity() const;
    int64_t
    getCapacity() const;

    /**
     * Set the Capacity of the Disk in bytes. (This can also be in any
@@ -93,7 +95,8 @@ namespace VDRIVE {
     *                any other scale, but has to be same for ExtentSize of
     *                Distributor)
     */
        void setCapacity(int64_t capacity);
    void
    setCapacity(int64_t capacity);

    /**
     * Get the Pointer to be used by developer instantiating this disk.
@@ -102,15 +105,18 @@ namespace VDRIVE {
     * @return Pointer to be used by developer instantiating this disk.
     *         May not be changed by Distributors!
     */
        void* getData() const;
    void*
    getData() const;

    /**
         * Set the Pointer to be used by developer instantiating this disk. May not be changed by Distributors!
     * Set the Pointer to be used by developer instantiating this disk. May not
     * be changed by Distributors!
     *
     * @param data Pointer to be used by developer instantiating this disk.
     *             May not be changed by Distributors!
     */
        void setData(void* data);
    void
    setData(void* data);

    /**
     * build an XML-Version of this object
@@ -118,14 +124,16 @@ namespace VDRIVE {
     * @param doc the document needed to create new XML Elements
     * @return a new Element containing the description of this object.
     */
        virtual xercesc::DOMElement* toXML(xercesc::DOMDocument* doc);
    virtual xercesc::DOMElement*
    toXML(xercesc::DOMDocument* doc);

    /**
     * Get the Root-Type of XML-Elements representing this class.
     *
     * @return the Root-Type of XML-Elements representing this class.
     */
        static std::string getXMLRootType() {
    static std::string
    getXMLRootType() {
        return std::string("Disk");
    }

@@ -135,7 +143,8 @@ namespace VDRIVE {
     * @param disks The disks to be stored
     * @param filename The name of the file the disks shall be stored in.
     */
        static void storeDiskList(std::list<Disk*>* disks, std::string filename);
    static void
    storeDiskList(std::list<Disk*>* disks, std::string filename);

    /**
     * Using this method it is possible to read a list of disks out of a
@@ -145,29 +154,32 @@ namespace VDRIVE {
     *
     * @return A list with the disks readen out of the file.
     */
        static std::list<Disk*>* loadDiskList(std::string filename);
    static std::list<Disk*>*
    loadDiskList(std::string filename);

#ifndef no_sqlite
    /**
         * Using this method it is possible to store a list of disks in a sqlite db file.
     * Using this method it is possible to store a list of disks in a sqlite db
     * file.
     *
     * @param disks The disks to be stored
     * @param filename The name of the file the disks shall be stored in.
     */
        static void storeDiskListDBFile(std::list<Disk*>* disks, std::string filename);
    static void
    storeDiskListDBFile(std::list<Disk*>* disks, std::string filename);

    /**
         * Using this method it is possible to read a list of disks out of a sqlite db
         * file.
     * Using this method it is possible to read a list of disks out of a sqlite
     * db file.
     *
     * @param filename The name of the file containing the disks.
     *
     * @return A list with the disks readen out of the file.
     */
        static std::list<Disk*>* loadDiskListDBFile(std::string filename);
    static std::list<Disk*>*
    loadDiskListDBFile(std::string filename);
#endif
private:

    /**
     * ID of the disk. Has to be unique all over this library.
     */
@@ -185,6 +197,5 @@ namespace VDRIVE {
     */
    void* data;
};
}
} // namespace VDRIVE
#endif /* _DISK_H */
+204 −181
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ namespace VDRIVE {
 */
class DistRandSlice : public Distributor {
public:
        
    // constants declaring the min and max values for the
    // virtual allocation space.
    // right now, it spans from 0 to 2^64-1 blocks/files/whatever
@@ -76,92 +75,119 @@ namespace VDRIVE {
    /**
     * @see Distributor::placeExtent
     */
        virtual std::list<Disk*>* placeExtent(int64_t virtualVolumeId, int64_t position);
    virtual std::list<Disk*>*
    placeExtent(int64_t virtualVolumeId, int64_t position);

    /**
     * @see Distributor::setConfiguration
     */
        virtual void setConfiguration(std::list<Disk*>* disks, int64_t extentsize, int32_t copies);
    virtual void
    setConfiguration(std::list<Disk*>* disks, int64_t extentsize,
                     int32_t copies);

    /**
     * @see Distributor::setDisks
     */
        virtual void setDisks(std::list<Disk*>* disks);
    virtual void
    setDisks(std::list<Disk*>* disks);

    /**
     * @see Distributor::toXML
     */
        virtual xercesc::DOMElement* toXML(xercesc::DOMDocument* doc) const;
    virtual xercesc::DOMElement*
    toXML(xercesc::DOMDocument* doc) const;

    /**
     * @see Distributor::getDisks
     */
        virtual std::list<Disk*>* getDisks() const;
    virtual std::list<Disk*>*
    getDisks() const;

    /**
     * @see Distributor::getExtentsize
     */
        virtual int64_t getExtentsize() const {
    virtual int64_t
    getExtentsize() const {
        return m_extentsize;
    }

    /**
     * @see Distributor::getCopies
     */
        virtual int32_t getCopies() const {
    virtual int32_t
    getCopies() const {
        return m_copies;
    }

    /**
     * @return the number of partitions currently in the system
     */
		uint64_t getNumPartitions() const {
    uint64_t
    getNumPartitions() const {
        return m_num_partitions;
    }

    /**
     * @return the number of intervals currently in the system
     */
		uint64_t getNumIntervals() const;
    uint64_t
    getNumIntervals() const;

    /**
     * Get the Root-Type of XML-Elements representing this class.
     *
     * @return the Root-Type of XML-Elements representing this class.
     */
        static std::string getXMLRootType() {
    static std::string
    getXMLRootType() {
        return std::string("RandSlice");
    }

private:
    void
    cleanup(void);

        void cleanup(void);
        
		void create_partitions(std::list<Disk*>* disks);
    void
    create_partitions(std::list<Disk*>* disks);

		void add_partitions(std::list<Disk*>* disks);
    void
    add_partitions(std::list<Disk*>* disks);

		void redistribute(std::tr1::unordered_map<uint64_t, uint64_t>& old_partitions,
    void
    redistribute(
            std::tr1::unordered_map<uint64_t, uint64_t>& old_partitions,
            const std::list<std::pair<uint64_t, uint64_t>>& new_partitions);

		void collect_free_space(std::tr1::unordered_map<uint64_t, uint64_t>& old_partitions,
    void
    collect_free_space(
            std::tr1::unordered_map<uint64_t, uint64_t>& old_partitions,
            std::list<std::pair<uint64_t, uint64_t>>& free_space);

		void collect_free_space_even_odd(std::tr1::unordered_map<uint64_t, uint64_t>& old_partitions,
    void
    collect_free_space_even_odd(
            std::tr1::unordered_map<uint64_t, uint64_t>& old_partitions,
            std::list<std::pair<uint64_t, uint64_t>>& free_space);

		void reuse_free_space(std::list< std::pair<uint64_t, uint64_t> >& free_space,
    void
    reuse_free_space(
            std::list<std::pair<uint64_t, uint64_t>>& free_space,
            const std::list<std::pair<uint64_t, uint64_t>>& new_partitions);

		void reuse_free_space_sort(std::list< std::pair<uint64_t, uint64_t> >& free_space,
    void
    reuse_free_space_sort(
            std::list<std::pair<uint64_t, uint64_t>>& free_space,
            const std::list<std::pair<uint64_t, uint64_t>>& new_partitions);


#if defined DEBUG
        void dump_intervals(void);
        void dump_free_space(const std::list< std::pair<uint64_t, uint64_t> >& l) const;
        void verify_partitions(void);
        std::vector<uint64_t> compute_interval_sizes(void);
    void
    dump_intervals(void);
    void
    dump_free_space(const std::list<std::pair<uint64_t, uint64_t>>& l) const;
    void
    verify_partitions(void);
    std::vector<uint64_t>
    compute_interval_sizes(void);
#endif

    /**
@@ -215,9 +241,6 @@ namespace VDRIVE {
     * sort free intervals decreasingly when assimilating free space
     */
    bool m_use_sorted_assimilation;
        

};
}
} // namespace VDRIVE
#endif /* _DISTRANDSLICE_H */
+94 −68
Original line number Diff line number Diff line
@@ -62,34 +62,40 @@ Disk::Disk(xercesc::DOMElement* data) {
    // TODO private_data
}

Disk::~Disk() {
}
Disk::~Disk() {}

void* Disk::getData() const {
void*
Disk::getData() const {
    return this->data;
}

void Disk::setData(void* data) {
void
Disk::setData(void* data) {
    this->data = data;
}

int64_t Disk::getId() const {
int64_t
Disk::getId() const {
    return this->id;
}

void Disk::setId(int64_t id) {
void
Disk::setId(int64_t id) {
    this->id = id;
}

int64_t Disk::getCapacity() const {
int64_t
Disk::getCapacity() const {
    return this->capacity;
}

void Disk::setCapacity(int64_t capacity) {
void
Disk::setCapacity(int64_t capacity) {
    this->capacity = capacity;
}

xercesc::DOMElement* Disk::toXML(xercesc::DOMDocument* doc) {
xercesc::DOMElement*
Disk::toXML(xercesc::DOMDocument* doc) {
    xercesc::DOMElement* result;
    std::stringstream out;
    XMLCh *xmlString, *xmlString2;
@@ -123,7 +129,8 @@ xercesc::DOMElement* Disk::toXML(xercesc::DOMDocument* doc) {

#ifndef no_sqlite

void Disk::storeDiskListDBFile(std::list<Disk*>* disks, std::string filename) {
void
Disk::storeDiskListDBFile(std::list<Disk*>* disks, std::string filename) {
    sqlite3* db;
    std::stringstream out;

@@ -134,13 +141,17 @@ void Disk::storeDiskListDBFile(std::list<Disk*>* disks, std::string filename) {

    execQuery(db, string("create table disklist_meta (key text, value text)"));
    execQuery(db, string("insert into meta values('tabletype', 'disklist')"));
    out << "insert into disklist_meta values ('count', " << disks->size() << ")";
    out << "insert into disklist_meta values ('count', " << disks->size()
        << ")";
    execQuery(db, string(out.str()));
    out.str("");

    execQuery(db, string("create table disklist (id integer, capacity integer)"));
    for (std::list<Disk*>::iterator it = disks->begin(); it != disks->end(); it++) {
        out << "insert into disklist values (" << (*it)->getId() << ", " << (*it)->getCapacity() << ")";
    execQuery(db,
              string("create table disklist (id integer, capacity integer)"));
    for(std::list<Disk*>::iterator it = disks->begin(); it != disks->end();
        it++) {
        out << "insert into disklist values (" << (*it)->getId() << ", "
            << (*it)->getCapacity() << ")";
        execQuery(db, string(out.str()));
        out.str("");
    }
@@ -148,7 +159,8 @@ void Disk::storeDiskListDBFile(std::list<Disk*>* disks, std::string filename) {
    sqlite3_close(db);
}

std::list<Disk*> *Disk::loadDiskListDBFile(std::string filename) {
std::list<Disk*>*
Disk::loadDiskListDBFile(std::string filename) {
    sqlite3* db;
    sqlite3_stmt* query;
    int error;
@@ -156,7 +168,8 @@ std::list<Disk*> *Disk::loadDiskListDBFile(std::string filename) {

    db = loadDB(filename);

    error = sqlite3_prepare(db, "select id,capacity from disklist", -1, &query, 0);
    error = sqlite3_prepare(db, "select id,capacity from disklist", -1, &query,
                            0);
    if(error) {
        fprintf(stderr, "Could not read disklist: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
@@ -166,7 +179,8 @@ std::list<Disk*> *Disk::loadDiskListDBFile(std::string filename) {

    error = sqlite3_step(query);
    while(error == SQLITE_ROW) {
        Disk *d = new Disk(sqlite3_column_int64(query, 0), sqlite3_column_int64(query, 1), 0);
        Disk* d = new Disk(sqlite3_column_int64(query, 0),
                           sqlite3_column_int64(query, 1), 0);
        result->push_back(d);
        error = sqlite3_step(query);
    }
@@ -184,36 +198,42 @@ std::list<Disk*> *Disk::loadDiskListDBFile(std::string filename) {
}
#endif

void Disk::storeDiskList(std::list<Disk*>* disks, std::string filename) {
void
Disk::storeDiskList(std::list<Disk*>* disks, std::string filename) {
    XMLCh* xmlString;
    try {
        XMLPlatformUtils::Initialize();
    } catch(const XMLException& toCatch) {
        char* sysString = XMLString::transcode(toCatch.getMessage());
        XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
                << "  Exception message:"
                << sysString << XERCES_STD_QUALIFIER endl;
                                  << "  Exception message:" << sysString
                                  << XERCES_STD_QUALIFIER endl;
        XMLString::release(&sysString);
        abort();
    }

    try {
        xmlString = XMLString::transcode("Core");
        DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(xmlString);
        DOMImplementation* impl =
                DOMImplementationRegistry::getDOMImplementation(xmlString);
        XMLString::release(&xmlString);
        xmlString = XMLString::transcode("disklist");
        DOMDocument* doc = impl->createDocument(0, xmlString, 0);
        XMLString::release(&xmlString);
        DOMElement* rootElem = doc->getDocumentElement();
        for (std::list<Disk*>::iterator it = disks->begin(); it != disks->end(); it++) {
        for(std::list<Disk*>::iterator it = disks->begin(); it != disks->end();
            it++) {
            Disk* disk = *it;
            DOMElement* xml = disk->toXML(doc);
            rootElem->appendChild(xml);
        }
        DOMLSSerializer *theSerializer = ((DOMImplementationLS*) impl)->createLSSerializer();
        DOMLSOutput *theOutput = ((DOMImplementationLS*) impl)->createLSOutput();
        DOMLSSerializer* theSerializer =
                ((DOMImplementationLS*) impl)->createLSSerializer();
        DOMLSOutput* theOutput =
                ((DOMImplementationLS*) impl)->createLSOutput();
        xmlString = XMLString::transcode(filename.c_str());
        LocalFileFormatTarget *myFormTarget = new LocalFileFormatTarget(xmlString);
        LocalFileFormatTarget* myFormTarget =
                new LocalFileFormatTarget(xmlString);
        XMLString::release(&xmlString);
        theOutput->setByteStream(myFormTarget);
        theSerializer->write(doc, theOutput);
@@ -225,16 +245,17 @@ void Disk::storeDiskList(std::list<Disk*>* disks, std::string filename) {
    } catch(const XMLException& toCatch) {
        char* sysString = XMLString::transcode(toCatch.getMessage());
        XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
                << "  Exception message:"
                << sysString << XERCES_STD_QUALIFIER endl;
                                  << "  Exception message:" << sysString
                                  << XERCES_STD_QUALIFIER endl;
        XMLString::release(&sysString);
        XMLPlatformUtils::Terminate();
        abort();
    } catch(const DOMException& toCatch) {
        char* sysString = XMLString::transcode(toCatch.getMessage());
        XERCES_STD_QUALIFIER cerr << "DOMError during Xerces-c Initialization.\n"
                << "  Exception message:"
                << sysString << XERCES_STD_QUALIFIER endl;
        XERCES_STD_QUALIFIER cerr
                << "DOMError during Xerces-c Initialization.\n"
                << "  Exception message:" << sysString
                << XERCES_STD_QUALIFIER endl;
        XMLString::release(&sysString);
        XMLPlatformUtils::Terminate();
        abort();
@@ -245,15 +266,16 @@ void Disk::storeDiskList(std::list<Disk*>* disks, std::string filename) {
    } catch(const XMLException& toCatch) {
        char* sysString = XMLString::transcode(toCatch.getMessage());
        XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
                << "  Exception message:"
                << sysString << XERCES_STD_QUALIFIER endl;
                                  << "  Exception message:" << sysString
                                  << XERCES_STD_QUALIFIER endl;
        XMLString::release(&sysString);
        XMLPlatformUtils::Terminate();
        abort();
    }
}

std::list<Disk*>* Disk::loadDiskList(std::string filename) {
std::list<Disk*>*
Disk::loadDiskList(std::string filename) {
    xercesc::DOMNode* n;
    XMLCh* xmlString;
    std::list<Disk*>* disks = 0;
@@ -264,8 +286,8 @@ std::list<Disk*>* Disk::loadDiskList(std::string filename) {
    } catch(const XMLException& toCatch) {
        char* sysString = XMLString::transcode(toCatch.getMessage());
        XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
                << "  Exception message:"
                << sysString << XERCES_STD_QUALIFIER endl;
                                  << "  Exception message:" << sysString
                                  << XERCES_STD_QUALIFIER endl;
        XMLString::release(&sysString);
        return 0;
    }
@@ -273,9 +295,13 @@ std::list<Disk*>* Disk::loadDiskList(std::string filename) {
    try {
        disks = new std::list<Disk*>();
        xmlString = XMLString::transcode("Core");
        DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(xmlString);
        DOMImplementation* impl =
                DOMImplementationRegistry::getDOMImplementation(xmlString);
        XMLString::release(&xmlString);
        DOMLSParser *parser = ((DOMImplementationLS*) impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
        DOMLSParser* parser =
                ((DOMImplementationLS*) impl)
                        ->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS,
                                         0);
        DOMDocument* doc = 0;
        DOMElement *rootElem, *diskElem;
        parser->resetDocumentPool();
@@ -300,8 +326,8 @@ std::list<Disk*>* Disk::loadDiskList(std::string filename) {
    } catch(const XMLException& toCatch) {
        char* sysString = XMLString::transcode(toCatch.getMessage());
        XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
                << "  Exception message:"
                << sysString << XERCES_STD_QUALIFIER endl;
                                  << "  Exception message:" << sysString
                                  << XERCES_STD_QUALIFIER endl;
        if(disks != 0) {
            delete disks;
        }
@@ -315,8 +341,8 @@ std::list<Disk*>* Disk::loadDiskList(std::string filename) {
    } catch(const XMLException& toCatch) {
        char* sysString = XMLString::transcode(toCatch.getMessage());
        XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
                << "  Exception message:"
                << sysString << XERCES_STD_QUALIFIER endl;
                                  << "  Exception message:" << sysString
                                  << XERCES_STD_QUALIFIER endl;
        XMLString::release(&sysString);
    }
    return disks;
+324 −318

File changed.

Preview size limit exceeded, changes collapsed.