return errorcode;
}
+static void _dp_client_clear_stale_db(dp_client_fmt *client)
+{
+ TRACE_DEBUG("Clear the stale DB data.");
+ int errorcode = DP_ERROR_NONE;
+ if (client && client->dbhandle != 0) {
+ // maintain only 1000 rows for each client
+ if (dp_db_limit_rows(client->dbhandle,
+ DP_TABLE_LOGGING, DP_LOG_DB_LIMIT_ROWS, &errorcode) < 0)
+ TRACE_INFO("limit rows error:%s", dp_print_errorcode(errorcode));
+ // maintain for 48 hours
+ if (dp_db_limit_time(client->dbhandle,
+ DP_TABLE_LOGGING, DP_CARE_CLIENT_INFO_PERIOD, &errorcode) < 0)
+ TRACE_INFO("limit rows error:%s", dp_print_errorcode(errorcode));
+ }
+}
+
static int __dp_request_read_int(int sock, dp_ipc_fmt *ipc_info, int *value)
{
int errorcode = DP_ERROR_NONE;
if (client->dbhandle == 0 || dp_db_check_connection(client->dbhandle) < 0) {
if (dp_db_open_client(&client->dbhandle, slot->pkgname, &errorcode) < 0) {
- TRACE_ERROR("failed to open database for sock:%d errorcode:%s", client_sock, dp_print_errorcode(errorcode));
+ TRACE_ERROR("failed to open database for sock:%d errorcode:%s",
+ client_sock, dp_print_errorcode(errorcode));
if (dp_ipc_query(client->channel, ipc_info->id,
ipc_info->section, ipc_info->property, errorcode, 0) < 0) {
TRACE_ERROR("check ipc sock:%d", client->channel);
TRACE_ERROR("[EXCEPTION]");
break;
} else {
-
- // timeout
+ TRACE_ERROR("[TIMEOUT]");
if (CLIENT_MUTEX_TRYLOCK(&slot->mutex) == 0) {
// 1. clear zombie requests. clean requests finished. paused or ready for long time
dp_client_clear_requests(slot);
- if (client->dbhandle != 0) {
- int sql_errorcode = DP_ERROR_NONE;
- // 2. maintain only 1000 rows for each client
- if (dp_db_limit_rows(client->dbhandle, DP_TABLE_LOGGING, DP_LOG_DB_LIMIT_ROWS, &sql_errorcode) < 0)
- TRACE_INFO("limit rows error:%s", dp_print_errorcode(sql_errorcode));
- // 3. maintain for 48 hours
- if (dp_db_limit_time(client->dbhandle, DP_TABLE_LOGGING, DP_CARE_CLIENT_INFO_PERIOD, &sql_errorcode) < 0)
- TRACE_INFO("limit rows error:%s", dp_print_errorcode(sql_errorcode));
- }
- // 4. if no requests, exit by itself.
+ // 2. if no requests, exit by itself.
if (slot->client.requests == NULL) {
TRACE_DEBUG("no requests");
CLIENT_MUTEX_UNLOCK(&slot->mutex);
}
} // while (slot != NULL && client_sock >= 0 && ....)
+ _dp_client_clear_stale_db(client);
+
if (client_sock >= 0 && client_sock < FD_SETSIZE) {
FD_CLR(client_sock, &imask);
FD_CLR(client_sock, &emask);
sqlite3_stmt *stmt = NULL;
char *query = sqlite3_mprintf("DELETE FROM %s WHERE %s NOT IN (SELECT %s FROM %s ORDER BY %s ASC LIMIT ?)", table, DP_DB_COL_ID, DP_DB_COL_ID, table, DP_DB_COL_CREATE_TIME);
DP_DB_BUFFER_NULL_CHECK(query);
- //TRACE_DEBUG("debug query:%s", query);
+ TRACE_DEBUG("debug query:%s", query);
errorcode = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
sqlite3_free(query);
DP_DB_BASIC_EXCEPTION_CHECK;
sqlite3_stmt *stmt = NULL;
char *query = sqlite3_mprintf("DELETE FROM %s WHERE %s < DATETIME('now','-%d hours')", table, DP_DB_COL_CREATE_TIME, hours);
DP_DB_BUFFER_NULL_CHECK(query);
- //TRACE_DEBUG("debug query:%s", query);
+ TRACE_DEBUG("debug query:%s", query);
errorcode = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
sqlite3_free(query);
DP_DB_BASIC_EXCEPTION_CHECK;