From 2b702b48d6ad07e31a01e487b04a537158dce757 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 16 Sep 2010 04:47:17 -0700 Subject: [PATCH] need to clear CID of record in DB when killing corresponding in-memory cref or reconnect will fail. --- xwords4/relay/crefmgr.cpp | 3 ++- xwords4/relay/dbmgr.cpp | 14 +++++++++++++- xwords4/relay/dbmgr.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/xwords4/relay/crefmgr.cpp b/xwords4/relay/crefmgr.cpp index 869994e50..18186af49 100644 --- a/xwords4/relay/crefmgr.cpp +++ b/xwords4/relay/crefmgr.cpp @@ -482,6 +482,7 @@ CRefMgr::Recycle_locked( CookieRef* cref ) { logf( XW_LOGINFO, "%s(cref=%p,cookie=%s)", __func__, cref, cref->Cookie() ); CookieID id = cref->GetCookieID(); + DBMgr::Get()->ClearCID( cref->ConnName() ); cref->Clear(); addToFreeList( cref ); @@ -501,7 +502,7 @@ CRefMgr::Recycle_locked( CookieRef* cref ) } ++iter; } - + assert( iter != m_cookieMap.end() ); /* we found something */ #ifdef RELAY_HEARTBEAT if ( m_cookieMap.size() == 0 ) { diff --git a/xwords4/relay/dbmgr.cpp b/xwords4/relay/dbmgr.cpp index 0ed87c219..446f74ba4 100644 --- a/xwords4/relay/dbmgr.cpp +++ b/xwords4/relay/dbmgr.cpp @@ -52,7 +52,7 @@ DBMgr::DBMgr() /* Now figure out what the largest cid currently is. There must be a way to get postgres to do this for me.... */ - /* const char* query = "SELECT cid FROM games ORDER BY - cid LIMIT 1"; */ + /* const char* query = "SELECT cid FROM games ORDER BY cid DESC LIMIT 1"; */ /* PGresult* result = PQexec( m_pgconn, query ); */ /* if ( 0 == PQntuples( result ) ) { */ /* m_nextCID = 1; */ @@ -191,6 +191,18 @@ DBMgr::AddCID( const char* const connName, CookieID cid ) execSql( query ); } +void +DBMgr::ClearCID( const char* connName ) +{ + const char* fmt = "UPDATE " TABLE_NAME " SET cid = null " + "WHERE connName = '%s'"; + char query[256]; + snprintf( query, sizeof(query), fmt, connName ); + logf( XW_LOGINFO, "%s: query: %s", __func__, query ); + + execSql( query ); +} + void DBMgr::ClearCIDs( void ) { diff --git a/xwords4/relay/dbmgr.h b/xwords4/relay/dbmgr.h index c509c58c1..aecb23253 100644 --- a/xwords4/relay/dbmgr.h +++ b/xwords4/relay/dbmgr.h @@ -43,6 +43,7 @@ class DBMgr { void AddPlayers( const char* const connName, int nToAdd ); void AddCID( const char* connName, CookieID cid ); + void ClearCID( const char* connName ); private: DBMgr();