Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
017c90de
Commit
017c90de
authored
Dec 13, 2019
by
Cedric CAFFY
Browse files
cta-catalogue-schema-verify use only 1 connection per database
parent
68d58713
Changes
9
Hide whitespace changes
Inline
Side-by-side
catalogue/CatalogueMetadataGetter.cpp
View file @
017c90de
...
...
@@ -21,45 +21,72 @@
namespace
cta
{
namespace
catalogue
{
CatalogueMetadataGetter
::
CatalogueMetadataGetter
(
cta
::
rdbms
::
ConnPool
&
connPool
)
:
m_connPool
(
connPool
){}
CatalogueMetadataGetter
::
CatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
&
conn
)
:
m_conn
(
conn
){}
std
::
string
CatalogueMetadataGetter
::
getCatalogueVersion
(){
std
::
string
schemaVersion
;
const
char
*
const
sql
=
"SELECT "
"CTA_CATALOGUE.SCHEMA_VERSION_MAJOR AS SCHEMA_VERSION_MAJOR,"
"CTA_CATALOGUE.SCHEMA_VERSION_MINOR AS SCHEMA_VERSION_MINOR "
"FROM "
"CTA_CATALOGUE"
;
auto
stmt
=
m_conn
.
createStmt
(
sql
);
auto
rset
=
stmt
.
executeQuery
();
if
(
rset
.
next
())
{
schemaVersion
+=
std
::
to_string
(
rset
.
columnUint64
(
"SCHEMA_VERSION_MAJOR"
));
schemaVersion
+=
"."
;
schemaVersion
+=
std
::
to_string
(
rset
.
columnUint64
(
"SCHEMA_VERSION_MINOR"
));
return
schemaVersion
;
}
else
{
throw
exception
::
Exception
(
"SCHEMA_VERSION_MAJOR,SCHEMA_VERSION_MINOR not found in the CTA_CATALOGUE"
);
}
}
CatalogueMetadataGetter
::~
CatalogueMetadataGetter
()
{}
SQLiteCatalogueMetadataGetter
::
SQLiteCatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
Pool
&
conn
Pool
)
:
CatalogueMetadataGetter
(
conn
Pool
){}
SQLiteCatalogueMetadataGetter
::
SQLiteCatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
&
conn
)
:
CatalogueMetadataGetter
(
conn
){}
SQLiteCatalogueMetadataGetter
::~
SQLiteCatalogueMetadataGetter
(){}
std
::
list
<
std
::
string
>
SQLiteCatalogueMetadataGetter
::
getIndexNames
()
{
rdbms
::
Conn
connection
=
m_connPool
.
getConn
();
std
::
list
<
std
::
string
>
indexNames
=
connection
.
getIndexNames
();
connection
.
closeUnderlyingStmtsAndConn
();
std
::
list
<
std
::
string
>
indexNames
=
m_conn
.
getIndexNames
();
indexNames
.
remove_if
([](
std
::
string
&
indexName
){
return
((
indexName
.
find
(
"sqlite_autoindex"
)
!=
std
::
string
::
npos
));
});
return
indexNames
;
}
OracleCatalogueMetadataGetter
::
OracleCatalogueMetadataGetter
(
cta
::
rdbms
::
ConnPool
&
connPool
)
:
CatalogueMetadataGetter
(
connPool
){}
std
::
list
<
std
::
string
>
SQLiteCatalogueMetadataGetter
::
getTableNames
(){
return
std
::
list
<
std
::
string
>
();
}
OracleCatalogueMetadataGetter
::
OracleCatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
&
conn
)
:
CatalogueMetadataGetter
(
conn
){}
OracleCatalogueMetadataGetter
::~
OracleCatalogueMetadataGetter
(){}
std
::
list
<
std
::
string
>
OracleCatalogueMetadataGetter
::
getIndexNames
()
{
rdbms
::
Conn
connection
=
m_connPool
.
getConn
();
std
::
list
<
std
::
string
>
indexNames
=
connection
.
getIndexNames
();
connection
.
closeUnderlyingStmtsAndConn
();
std
::
list
<
std
::
string
>
indexNames
=
m_conn
.
getIndexNames
();
indexNames
.
remove_if
([](
std
::
string
&
indexName
){
return
((
indexName
.
find
(
"_UN"
)
!=
std
::
string
::
npos
)
||
(
indexName
.
find
(
"PK"
)
!=
std
::
string
::
npos
)
||
(
indexName
.
find
(
"_LLN"
)
!=
std
::
string
::
npos
));
});
return
indexNames
;
}
std
::
list
<
std
::
string
>
OracleCatalogueMetadataGetter
::
getTableNames
()
{
return
std
::
list
<
std
::
string
>
();
}
CatalogueMetadataGetter
*
CatalogueMetadataGetterFactory
::
create
(
const
rdbms
::
Login
::
DbType
dbType
,
cta
::
rdbms
::
Conn
Pool
&
conn
Pool
)
{
CatalogueMetadataGetter
*
CatalogueMetadataGetterFactory
::
create
(
const
rdbms
::
Login
::
DbType
dbType
,
cta
::
rdbms
::
Conn
&
conn
)
{
typedef
rdbms
::
Login
::
DbType
DbType
;
switch
(
dbType
){
case
DbType
::
DBTYPE_IN_MEMORY
:
case
DbType
::
DBTYPE_SQLITE
:
return
new
SQLiteCatalogueMetadataGetter
(
conn
Pool
);
return
new
SQLiteCatalogueMetadataGetter
(
conn
);
case
DbType
::
DBTYPE_ORACLE
:
return
new
OracleCatalogueMetadataGetter
(
conn
Pool
);
return
new
OracleCatalogueMetadataGetter
(
conn
);
default:
return
nullptr
;
}
...
...
catalogue/CatalogueMetadataGetter.hpp
View file @
017c90de
...
...
@@ -29,30 +29,34 @@ namespace catalogue {
class
CatalogueMetadataGetter
{
public:
protected:
rdbms
::
Conn
Pool
&
m_conn
Pool
;
rdbms
::
Conn
&
m_conn
;
public:
CatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
Pool
&
conn
Pool
);
CatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
&
conn
);
virtual
~
CatalogueMetadataGetter
();
std
::
string
getCatalogueVersion
();
virtual
std
::
list
<
std
::
string
>
getIndexNames
()
=
0
;
virtual
std
::
list
<
std
::
string
>
getTableNames
()
=
0
;
};
class
SQLiteCatalogueMetadataGetter
:
public
CatalogueMetadataGetter
{
public:
SQLiteCatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
Pool
&
conn
Pool
);
SQLiteCatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
&
conn
);
virtual
~
SQLiteCatalogueMetadataGetter
();
std
::
list
<
std
::
string
>
getIndexNames
()
override
;
std
::
list
<
std
::
string
>
getTableNames
()
override
;
};
class
OracleCatalogueMetadataGetter
:
public
CatalogueMetadataGetter
{
public:
OracleCatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
Pool
&
conn
Pool
);
OracleCatalogueMetadataGetter
(
cta
::
rdbms
::
Conn
&
conn
);
virtual
~
OracleCatalogueMetadataGetter
();
std
::
list
<
std
::
string
>
getIndexNames
()
override
;
std
::
list
<
std
::
string
>
getTableNames
()
override
;
};
class
CatalogueMetadataGetterFactory
{
public:
static
CatalogueMetadataGetter
*
create
(
const
rdbms
::
Login
::
DbType
dbType
,
cta
::
rdbms
::
Conn
Pool
&
conn
Pool
);
static
CatalogueMetadataGetter
*
create
(
const
rdbms
::
Login
::
DbType
dbType
,
cta
::
rdbms
::
Conn
&
conn
);
};
}}
\ No newline at end of file
catalogue/SQLiteSchemaComparer.cpp
View file @
017c90de
...
...
@@ -25,13 +25,13 @@
namespace
cta
{
namespace
catalogue
{
SQLiteSchemaComparer
::
SQLiteSchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
const
std
::
string
&
schemaVersion
,
rdbms
::
Conn
Pool
&
catalogueConn
Pool
)
:
SchemaComparer
(
catalogueDbType
,
schemaVersion
,
catalogueConn
Pool
)
{
SQLiteSchemaComparer
::
SQLiteSchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
rdbms
::
Conn
&
catalogueConn
)
:
SchemaComparer
(
catalogueDbType
,
catalogueConn
)
{
log
::
DummyLogger
dl
(
"dummy"
,
"dummy"
);
auto
login
=
rdbms
::
Login
::
parseString
(
"in_memory"
);
m_sqliteConnPool
.
reset
(
new
rdbms
::
ConnPool
(
login
,
1
));
m_catalogueMetadataGetter
.
reset
(
CatalogueMetadataGetterFactory
::
create
(
catalogueDbType
,
catalogueConnPool
));
m_sqliteSchemaMetadataGetter
.
reset
(
new
SQLiteCatalogueMetadataGetter
(
*
m_sqliteConnPool
));
rdbms
::
ConnPool
connPool
(
login
,
1
);
rdbms
::
Conn
conn
=
connPool
.
getConn
();
m_sqliteConn
=
std
::
move
(
conn
);
m_sqliteSchemaMetadataGetter
.
reset
(
new
SQLiteCatalogueMetadataGetter
(
m_sqliteConn
));
}
SQLiteSchemaComparer
::~
SQLiteSchemaComparer
()
{
...
...
@@ -41,15 +41,26 @@ SchemaComparerResult SQLiteSchemaComparer::compare(){
SchemaComparerResult
res
;
insertSchemaInSQLite
();
res
+=
compareIndexes
();
res
+=
compareTables
();
return
res
;
}
SchemaComparerResult
SQLiteSchemaComparer
::
compareTables
(){
std
::
list
<
std
::
string
>
catalogueTables
=
m_catalogueMetadataGetter
->
getTableNames
();
std
::
list
<
std
::
string
>
schemaTables
=
m_sqliteSchemaMetadataGetter
->
getTableNames
();
std
::
cout
<<
"catalogue tables = "
<<
std
::
endl
;
for
(
auto
&
catalogueTable
:
catalogueTables
){
std
::
cout
<<
catalogueTable
<<
std
::
endl
;
}
std
::
cout
<<
"schema tables = "
<<
std
::
endl
;
for
(
auto
&
schemaTable
:
schemaTables
){
std
::
cout
<<
schemaTable
<<
std
::
endl
;
}
return
SchemaComparerResult
();
}
void
SQLiteSchemaComparer
::
insertSchemaInSQLite
()
{
cta
::
catalogue
::
SQLiteSchemaInserter
schemaInserter
(
m_
s
chemaVersion
,
m_dbType
,
"/home/cedric/CTA/catalogue/"
,
*
m_sqliteConn
Pool
);
cta
::
catalogue
::
SQLiteSchemaInserter
schemaInserter
(
m_
catalogueS
chemaVersion
,
m_dbType
,
"/home/cedric/CTA/catalogue/"
,
m_sqliteConn
);
schemaInserter
.
insert
();
}
...
...
catalogue/SQLiteSchemaComparer.hpp
View file @
017c90de
...
...
@@ -18,15 +18,13 @@
#pragma once
#include
"SchemaComparer.hpp"
#include
"SchemaCreatingSqliteCatalogue.hpp"
#include
"InMemoryCatalogue.hpp"
namespace
cta
{
namespace
catalogue
{
class
SQLiteSchemaComparer
:
public
SchemaComparer
{
public:
SQLiteSchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
const
std
::
string
&
schemaVersion
,
rdbms
::
Conn
Pool
&
catalogueConnPool
);
SQLiteSchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
rdbms
::
Conn
&
catalogueConnPool
);
SchemaComparerResult
compare
()
override
;
virtual
~
SQLiteSchemaComparer
();
...
...
@@ -34,7 +32,7 @@ private:
void
insertSchemaInSQLite
();
SchemaComparerResult
compareIndexes
();
SchemaComparerResult
compareTables
()
override
;
std
::
unique_ptr
<
rdbms
::
Conn
Pool
>
m_sqliteConn
Pool
;
rdbms
::
Conn
m_sqliteConn
;
std
::
unique_ptr
<
SQLiteCatalogueMetadataGetter
>
m_sqliteSchemaMetadataGetter
;
};
...
...
catalogue/SQLiteSchemaInserter.cpp
View file @
017c90de
...
...
@@ -27,7 +27,7 @@
namespace
cta
{
namespace
catalogue
{
SQLiteSchemaInserter
::
SQLiteSchemaInserter
(
const
std
::
string
&
schemaVersion
,
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
const
std
::
string
&
allVersionsSchemaDirectory
,
rdbms
::
Conn
Pool
&
sqliteConn
Pool
)
:
m_schemaVersion
(
schemaVersion
),
m_dbType
(
catalogueDbType
),
m_allVersionSchemaDirectory
(
allVersionsSchemaDirectory
),
m_sqliteCatalogueConn
Pool
(
sqliteConn
Pool
){}
SQLiteSchemaInserter
::
SQLiteSchemaInserter
(
const
std
::
string
&
schemaVersion
,
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
const
std
::
string
&
allVersionsSchemaDirectory
,
rdbms
::
Conn
&
sqliteConn
)
:
m_schemaVersion
(
schemaVersion
),
m_dbType
(
catalogueDbType
),
m_allVersionSchemaDirectory
(
allVersionsSchemaDirectory
),
m_sqliteCatalogueConn
(
sqliteConn
){}
SQLiteSchemaInserter
::~
SQLiteSchemaInserter
()
{}
...
...
@@ -43,9 +43,8 @@ void SQLiteSchemaInserter::insert() {
}
void
SQLiteSchemaInserter
::
executeStatements
(
const
std
::
list
<
std
::
string
>
&
stmts
){
rdbms
::
Conn
conn
=
m_sqliteCatalogueConnPool
.
getConn
();
for
(
auto
&
sqliteStatement
:
stmts
){
auto
stmt
=
c
onn
.
createStmt
(
sqliteStatement
);
auto
stmt
=
m_sqliteCatalogueC
onn
.
createStmt
(
sqliteStatement
);
stmt
.
executeNonQuery
();
}
}
...
...
catalogue/SQLiteSchemaInserter.hpp
View file @
017c90de
...
...
@@ -25,7 +25,7 @@ namespace catalogue {
class
SQLiteSchemaInserter
{
public:
SQLiteSchemaInserter
(
const
std
::
string
&
schemaVersion
,
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
const
std
::
string
&
allVersionsSchemaDirectory
,
rdbms
::
Conn
Pool
&
sqliteConn
Pool
);
SQLiteSchemaInserter
(
const
std
::
string
&
schemaVersion
,
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
const
std
::
string
&
allVersionsSchemaDirectory
,
rdbms
::
Conn
&
sqliteConn
);
void
insert
();
virtual
~
SQLiteSchemaInserter
();
private:
...
...
@@ -34,7 +34,7 @@ namespace catalogue {
std
::
string
m_schemaVersion
;
cta
::
rdbms
::
Login
::
DbType
m_dbType
;
std
::
string
m_allVersionSchemaDirectory
;
cta
::
rdbms
::
Conn
Pool
&
m_sqliteCatalogueConn
Pool
;
cta
::
rdbms
::
Conn
&
m_sqliteCatalogueConn
;
std
::
string
readSchemaFromFile
();
std
::
list
<
std
::
string
>
getAllStatementsFromSchema
(
const
std
::
string
&
schema
);
std
::
string
getDatabaseType
();
...
...
catalogue/SchemaComparer.cpp
View file @
017c90de
...
...
@@ -26,12 +26,13 @@
namespace
cta
{
namespace
catalogue
{
SchemaComparer
::
SchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
dbType
,
const
std
::
string
&
schemaVersion
,
rdbms
::
ConnPool
&
connPool
)
:
m_dbType
(
dbType
),
m_schemaVersion
(
schemaVersion
),
m_catalogueConnPool
(
connPool
){
m_catalogueMetadataGetter
.
reset
(
CatalogueMetadataGetterFactory
::
create
(
dbType
,
m_catalogueConnPool
));
SchemaComparer
::
SchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
dbType
,
rdbms
::
Conn
&
conn
)
:
m_dbType
(
dbType
),
m_catalogueConn
(
conn
){
m_catalogueMetadataGetter
.
reset
(
CatalogueMetadataGetterFactory
::
create
(
dbType
,
m_catalogueConn
));
m_catalogueSchemaVersion
=
m_catalogueMetadataGetter
->
getCatalogueVersion
();
}
std
::
string
SchemaComparer
::
getCatalogueVersion
(){
return
m_
s
chemaVersion
;
return
m_
catalogueS
chemaVersion
;
}
SchemaComparer
::~
SchemaComparer
()
{
...
...
catalogue/SchemaComparer.hpp
View file @
017c90de
...
...
@@ -33,15 +33,16 @@ namespace catalogue {
class
SchemaComparer
{
public:
SchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
const
std
::
string
&
schemaVersion
,
cta
::
rdbms
::
Conn
Pool
&
conn
Pool
);
SchemaComparer
(
const
cta
::
rdbms
::
Login
::
DbType
&
catalogueDbType
,
cta
::
rdbms
::
Conn
&
conn
);
virtual
~
SchemaComparer
();
virtual
SchemaComparerResult
compare
()
=
0
;
std
::
string
getCatalogueVersion
();
protected:
const
cta
::
rdbms
::
Login
::
DbType
&
m_dbType
;
const
std
::
string
&
m_
s
chemaVersion
;
cta
::
rdbms
::
Conn
Pool
&
m_catalogueConn
Pool
;
std
::
string
m_
catalogueS
chemaVersion
;
cta
::
rdbms
::
Conn
&
m_catalogueConn
;
std
::
unique_ptr
<
cta
::
catalogue
::
CatalogueMetadataGetter
>
m_catalogueMetadataGetter
;
private:
virtual
SchemaComparerResult
compareTables
()
=
0
;
virtual
SchemaComparerResult
compareIndexes
()
=
0
;
...
...
catalogue/VerifySchemaCmd.cpp
View file @
017c90de
...
...
@@ -63,7 +63,7 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
}
auto
login
=
rdbms
::
Login
::
parseFile
(
cmdLineArgs
.
dbConfigPath
);
const
uint64_t
maxNbConns
=
1
0
;
const
uint64_t
maxNbConns
=
1
;
rdbms
::
ConnPool
connPool
(
login
,
maxNbConns
);
auto
conn
=
connPool
.
getConn
();
...
...
@@ -74,22 +74,13 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
return
1
;
}
log
::
DummyLogger
dummyLog
(
"dummy"
,
"dummy"
);
const
auto
catalogueFactory
=
CatalogueFactoryFactory
::
create
(
dummyLog
,
login
,
maxNbConns
,
maxNbConns
);
auto
catalogue
=
catalogueFactory
->
create
();
//Get the version of the catalogue
std
::
map
<
std
::
string
,
uint64_t
>
schemaVersion
=
catalogue
->
getSchemaVersion
();
uint64_t
schemaVersionMajor
=
schemaVersion
.
at
(
"SCHEMA_VERSION_MAJOR"
);
uint64_t
schemaVersionMinor
=
schemaVersion
.
at
(
"SCHEMA_VERSION_MINOR"
);
std
::
string
schemaVersionStr
=
std
::
to_string
(
schemaVersionMajor
)
+
"."
+
std
::
to_string
(
schemaVersionMinor
);
std
::
unique_ptr
<
cta
::
catalogue
::
SchemaComparer
>
schemaComparer
;
schemaComparer
.
reset
(
new
cta
::
catalogue
::
SQLiteSchemaComparer
(
login
.
dbType
,
schemaVersionStr
,
connPool
));
schemaComparer
.
reset
(
new
cta
::
catalogue
::
SQLiteSchemaComparer
(
login
.
dbType
,
conn
));
cta
::
catalogue
::
SchemaComparerResult
res
=
schemaComparer
->
compare
();
std
::
cout
<<
"Schema version : "
<<
schemaComparer
->
getCatalogueVersion
()
<<
std
::
endl
;
std
::
cout
<<
"Status of the checking : "
<<
cta
::
catalogue
::
SchemaComparerResult
::
StatusToString
(
res
.
getStatus
())
<<
std
::
endl
;
res
.
printDiffs
();
schemaComparer
.
release
();
/*std::unique_ptr<CatalogueSchema> schema;
switch(login.dbType) {
case rdbms::Login::DBTYPE_IN_MEMORY:
...
...
@@ -122,9 +113,9 @@ int VerifySchemaCmd::exceptionThrowingMain(const int argc, char *const *const ar
}
std::cerr << "Checking schema version..." << std::endl;
//
log::DummyLogger dummyLog("dummy", "dummy");
//
const auto catalogueFactory = CatalogueFactoryFactory::create(dummyLog, login, maxNbConns, maxNbConns);
//
const auto catalogue = catalogueFactory->create();
log::DummyLogger dummyLog("dummy", "dummy");
const auto catalogueFactory = CatalogueFactoryFactory::create(dummyLog, login, maxNbConns, maxNbConns);
const auto catalogue = catalogueFactory->create();
const auto schemaDbVersion = catalogue->getSchemaVersion();
const auto schemaVersion = schema->getSchemaVersion();
const VerifyStatus verifySchemaStatus = verifySchemaVersion(schemaVersion, schemaDbVersion);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment