Commit f612e821 authored by Cedric CAFFY's avatar Cedric CAFFY
Browse files

Created an objectstoretool to create a missing repack index

parent 5fb2bd3a
......@@ -157,6 +157,11 @@ set_property(TARGET cta-objectstore-collect-orphaned-object APPEND PROPERTY INST
target_link_libraries(cta-objectstore-collect-orphaned-object
${PROTOBUF3_LIBRARIES} ctaobjectstore ctacommon ctacatalogue)
add_executable(cta-objectstore-create-missing-repack-index cta-objectstore-create-missing-repack-index.cpp)
set_property(TARGET cta-objectstore-create-missing-repack-index APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH})
target_link_libraries(cta-objectstore-create-missing-repack-index
${PROTOBUF3_LIBRARIES} ctaobjectstore ctacommon)
install(TARGETS cta-objectstore-initialize cta-objectstore-list cta-objectstore-dump-object cta-objectstore-unfollow-agent
cta-objectstore-dereference-removed-queues cta-objectstore-collect-orphaned-object
DESTINATION usr/bin)
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* This program will make sure every queue listed in the root entry does exist and
* will remove reference for the ones that do not. This utility was created to quickly
* unblock tape servers after changing the ArchiveQueue schema during development.
*/
#include "Agent.hpp"
#include "AgentRegister.hpp"
#include "AgentReference.hpp"
#include "BackendFactory.hpp"
#include "BackendVFS.hpp"
#include "common/Configuration.hpp"
#include "common/log/StdoutLogger.hpp"
#include "common/log/LogContext.hpp"
#include "common/utils/utils.hpp"
#include "RootEntry.hpp"
#include <iostream>
#include <stdexcept>
int main(int argc, char ** argv) {
try {
cta::log::StdoutLogger logger(cta::utils::getShortHostname(), "cta-objectstore-create-missing-repack-index");
cta::log::LogContext lc(logger);
std::unique_ptr<cta::objectstore::Backend> be;
if (2 == argc) {
be.reset(cta::objectstore::BackendFactory::createBackend(argv[1], logger).release());
} else if (1 == argc) {
cta::common::Configuration m_ctaConf("/etc/cta/cta-objectstore-tools.conf");
be = std::move(cta::objectstore::BackendFactory::createBackend(m_ctaConf.getConfEntString("ObjectStore", "BackendPath", nullptr), logger));
} else {
throw std::runtime_error("Wrong number of arguments: expected 0 or 1: [objectstoreURL]");
}
// If the backend is a VFS, make sure we don't delete it on exit.
// If not, nevermind.
try {
dynamic_cast<cta::objectstore::BackendVFS &>(*be).noDeleteOnExit();
} catch (std::bad_cast &){}
std::cout << "Object store path: " << be->getParams()->toURL() << std::endl;
// Open the root entry RW
std::cout << "Creating AgentReference for the creation of the repack index" << std::endl;
cta::objectstore::AgentReference agr("cta-objectstore-create-missing-repack-index", logger);
std::cout << "Creating Agent for the creation of the repack index" << std::endl;
cta::objectstore::Agent ag(agr.getAgentAddress(), *be);
std::cout << "Initializing agent" << std::endl;
ag.initialize();
std::cout << "Inserting agent" << std::endl;
ag.insertAndRegisterSelf(lc);
cta::objectstore::RootEntry re(*be);
cta::objectstore::ScopedExclusiveLock rel(re);
re.fetch();
try{
std::cout << "Trying to insert repack index" << std::endl;
std::string repackIndexAddress = re.addOrGetRepackIndexAndCommit(agr);
std::cout << "Repack index created. Address = " << repackIndexAddress << std::endl;
} catch(const cta::exception::Exception &e){
std::cout << "Repack index already exists, nothing to do." << std::endl;
}
} catch (std::exception & e) {
std::cerr << "Failed to create repack index: "
<< std::endl << e.what() << std::endl;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment