Deadlock opening a Berkeley DB database - berkeley-db

I'm trying to open two databases that where previously created. The program that created them crashed, and left transactions open. When I try to open the databases, it deadlocks in the 'txn->commit(0);' statement:
auto envFlags = DB_CREATE |
DB_INIT_LOCK |
DB_INIT_LOG |
DB_INIT_MPOOL |
DB_INIT_TXN;
dbEnv.open(dbHomePath.c_str(), envFlags, 0);
DbTxn *txn;
dbEnv.txn_begin(NULL, &txn, 0);
dbActive.open(txn, "db0.db", NULL, DB_BTREE, DB_CREATE, 0);
dbClosed.open(txn, "db1.db", NULL, DB_BTREE, DB_CREATE, 0);
txn->commit(0);
How can I cancel the transactions left open?

Related

With DBeaver, MariaDB Optimizer Trace a result irrelevant to the concerned query

With a non-root user on 10.5.18-MariaDB, we are trying to get the optimizer trace about the SQL query select * from eav_value ev; however, the result seems to be irrelevant, saying something about select database() AS DATABASE():
{
"steps": [
{
"join_preparation": {
"select_id": 1,
"steps": [
{
"expanded_query": "select database() AS `DATABASE()`"
}
]
}
},
{
"join_optimization": {
"select_id": 1,
"steps": []
}
},
{
"join_execution": {
"select_id": 1,
"steps": []
}
}
]
}
We also tried to get the optimizer traces for other queries but got the same result as above, regardless of the query.
If change to use the CLI connection, the system behaviour is OK. We prefer the GUI tools, e.g. DBeaver, though.
We are learning how to use the optimizer trace, so we wonder if we missed anything.
The commands used in the test:
select ##version
;
show create table INFORMATION_SCHEMA.OPTIMIZER_TRACE
;
set session OPTIMIZER_TRACE = "enabled=on"
;
select * from eav_value ev
;
select * from information_schema.OPTIMIZER_TRACE
;
set session OPTIMIZER_TRACE = "enabled=off"
;
DBeaver uses MariaDB Connector/J. It looks like this driver disconnects after completing the query.
Therefore, when getting for the optimizer trace, it is not the same session as the query before. The optimizer trace depends on the session.
We are still open to suggestions about how to keep DBeaver hold on to the same session and not to disconnect after each query.

How to really set foreground window using Winapi?

OS: Windows 10
I have very simple GUI application in Qt. In this app I only set the window name to "tmpAppName".
Now I would like to run the second app which set the first App to foreground ( tmpAppName ).
My second App:
auto hwndAppToForeground = FindWindowExA(0,0,0,"tmpAppName");
if(!hwndAppToForeground)
{
qDebug()<<"No window with name tmpAppName";
exit(0);
}
auto foregroundWindow = GetForegroundWindow();
Sleep(5000);
if(foregroundWindow!=hwndAppToForeground)
{
SetForegroundWindow(hwndAppToForeground);
SetActiveWindow(hwndAppToForeground);
SetFocus(hwndAppToForeground);
SetWindowPos(hwndAppToForeground, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
I using Sleep(5000) because during that time I set other application in the foreground ( for example Audacity ).
The line:
SetWindowPos(hwndAppToForeground, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
is very helpfull, but I get window in the foreground but not active and when I check which window is in the foreground I get something different then "tmpAppName":
And I would like to achieve:

sqlite commands possibly not working in qt

I am making a library management software using Qt and Sqlite3.
constructor:
db = QSqlDatabase :: addDatabase("QSQLITE");
model = new QSqlTableModel(this, db);
db.setDatabaseName(":/lib/libre coupe.db");
db.setHostName("Libre Coupe");
if(db.open())
{
QSqlQuery query(db);
if (! query.exec("CREATE TABLE IF NOT EXISTS books (NAME VARCHAR(100) NOT NULL, AUTHOR VARCHAR(100) NOT NULL, UID VARCHAR(100) NOT NULL) "))
{
QMessageBox::information(this, "title", "Unable to use Sqlite");
}
if(query.lastError().text() != " ")
QMessageBox::critical(this, "Oops", query.lastError().text());
model->setTable("books");
model->select();
model->setHeaderData(0, Qt::Horizontal, tr("Name") );
model->setHeaderData(1, Qt::Horizontal, tr("Author") );
model->setHeaderData(2, Qt::Horizontal, tr("Uid") );
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
if(!query.exec("SELECT * FROM books;"))
QMessageBox::critical(this, "Oops", query.lastError().text());
int i = 0;
while(query.next())
{
model->setData(model->index(i, 0), query.value(query.record().indexOf("NAME")));
model->setData(model->index(i, 1), query.value(query.record().indexOf("AUTHOR")));
model->setData(model->index(i, 2), query.value(query.record().indexOf("UID")));
++i;
}
}
else
QMessageBox::critical(this, "Oops!", "Could not open the database");\
I faced a problem that the database was not created automatically. So, i created it manually and added it to my resource so that it exists on every computer which uses my application.
I ran my app and went to the directory containing "libre coupe.db". There using the terminal, i found out that no table was created. I see no error message. My other functions like save don't work too while the same commands typed directly into Sqlite using terminal works as expected.
I even used the debugger and found that the program does enter the if condition i.e. the database opens successfully.
I used the following command to check if the table existed:
sqlite3 "libre coupe.db"
.tables
First line:
db.setDatabaseName(":/lib/libre coupe.db");
the starting ":" means you are trying to access an embedded binary resource using Qt's resource system.
However, SQLite databases cannot be stored in the Qt resource system. If your database is instead located at /lib/libre coupe.db, you should remove the colon at the beginning.

Cannot remove index in Titan over DynamoDB

I created a mixed index on Titan 1.0 with Dynamo DB backend and Elasticsearch and I'm trying to remove it using the following code
public static void removeIndex(TitanGraph graph, String indexStr) throws ExecutionException, InterruptedException {
TitanManagement m = graph.openManagement();
TitanGraphIndex nameIndex = m.getGraphIndex(indexStr);
Preconditions.checkState(nameIndex!=null, "index "+ indexStr +" doesn't exist");
TitanManagement.IndexJobFuture futureDisable = m.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX);
m.commit();
graph.tx().commit();
futureDisable.get();
// Block until the SchemaStatus transitions from to DISABLED
ManagementSystem.awaitGraphIndexStatus(graph, indexStr)
.status(SchemaStatus.DISABLED).call();
// Delete the index using TitanManagement
m = graph.openManagement();
nameIndex = m.getGraphIndex(indexStr);
TitanManagement.IndexJobFuture futureRemove =
m.updateIndex(nameIndex, SchemaAction.REMOVE_INDEX);
m.commit();
graph.tx().commit();
Preconditions.checkState(futureRemove!=null,
"Couldn't remove index/es because seems like indexes were not disabled."); // fails here.
futureRemove.get();
m = graph.openManagement();
nameIndex = m.getGraphIndex(indexStr);
Preconditions.checkArgument(nameIndex==null);
}
The key doesn't get removed. I get this warning indicating that the index never gets disabled.
---
INFO com.thinkaurelius.titan.graphdb.database.management.GraphIndexStatusWatcher - Some key(s) on index verticesIndex do not currently have status DISABLED: position=INSTALLED
INFO com.thinkaurelius.titan.graphdb.database.management.GraphIndexStatusWatcher - Timed out (PT1M) while waiting for index verticesIndex to converge on status DISABLED
[WARNING]
The code fails on the precondition test.
What am I doing wrong?
It turns out I was using position to define a property key which is a reserved keyword in DynamoDB.
The only way was to:
Delete all DynamoDB tables of Titan from the web console,
change 'position' to 'fieldPosition',
and start my code to create tables and indexes from scratch.

Autofetch behavior with firehose cursor, when SQL_SOPT_SS_CURSOR_OPTIONS option is set to SQL_CO_FIREHOSE_AF

On firehose cursor, when statement attribute SQL_SOPT_SS_CURSOR_OPTIONS is set to SQL_CO_FIREHOSE_AF, and the statement is executed, observed different behavior for autofetch which are mentioned below:
1) When SQLExecute is called first time it does not autofetch.
2) When SQLExecute is called second time on the same stament handle, after closing cursor using SQLFreestmt(hstmt, SQL_CLOSE), it autofetch 1 row with SQLExecute.
So what is the expected behavior, whether it should autofetch or not ? This seems to be bug in SQL Native client drivers.
Also I didn't see documentation for SQL_CO_FIREHOSE_AF but it is listed in sqlncli.h ?
code snippet with comments:
rc = SQLSetStmtAttr(hstmt1, (UWORD) SQL_SOPT_SS_CURSOR_OPTIONS, (SQLPOINTER) SQL_CO_FIREHOSE_AF, 0);
...
rc = SQLSetStmtAttr(hstmt1, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)1, 0);
// Execute first statement
rc = SQLExecute(hstmt1); // it does not autofetch the data.
...
rc = SQLFreeStmt(hstmt1, SQL_CLOSE);
...
rc = SQLSetStmtAttr(hstmt1, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)1, 0);
// Execute first statement
rc = SQLExecute(hstmt1); // it autofetch 1 record.
Thanks,
Mukesh

Resources