X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_session_shared.cpp;h=7118476cb9fa4c4ac3ca80ef5d6fd32c482be913;hb=51bd69f6e778ab83e4017172625c0decc8465e1b;hp=dbbd0fcd57ec8078cfe765ef812788a328e2698e;hpb=b9e82b9adecd1dbd44e54c28d6b0d1336721bfec;p=metaproxy-moved-to-github.git diff --git a/src/filter_session_shared.cpp b/src/filter_session_shared.cpp index dbbd0fc..7118476 100644 --- a/src/filter_session_shared.cpp +++ b/src/filter_session_shared.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2011 Index Data + Copyright (C) 2005-2012 Index Data Metaproxy 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 @@ -104,6 +104,7 @@ namespace metaproxy_1 { time_t m_time_last_use; mp::Package * m_close_package; ~BackendInstance(); + void timestamp(); }; // backends of some class (all with same InitKey) class SessionShared::BackendClass : boost::noncopyable { @@ -331,10 +332,15 @@ yf::SessionShared::BackendClass::get_backend( void yf::SessionShared::BackendClass::use_backend(BackendInstancePtr backend) { backend->m_in_use = true; - time(&backend->m_time_last_use); backend->m_sequence_this = m_sequence_top++; } +void yf::SessionShared::BackendInstance::timestamp() +{ + assert(m_in_use); + time(&m_time_last_use); +} + yf::SessionShared::BackendInstance::~BackendInstance() { delete m_close_package; @@ -528,6 +534,10 @@ bool yf::SessionShared::BackendSet::search( for (; it != m_databases.end(); it++) req->databaseNames[i++] = odr_strdup(odr, it->c_str()); + if (frontend_apdu->which == Z_APDU_searchRequest) + req->preferredRecordSyntax = + frontend_apdu->u.searchRequest->preferredRecordSyntax; + search_package.request() = apdu_req; search_package.move(); @@ -572,8 +582,8 @@ void yf::SessionShared::Frontend::override_set( BackendSetList::iterator set_it = (*it)->m_sets.begin(); for (; set_it != (*it)->m_sets.end(); set_it++) { - if (now >= (*set_it)->m_time_last_use && - now - (*set_it)->m_time_last_use > bc->m_backend_set_ttl) + if (now < (*set_it)->m_time_last_use || + now - (*set_it)->m_time_last_use >= bc->m_backend_set_ttl) { found_backend = *it; result_set_id = (*set_it)->m_result_set_id; @@ -683,6 +693,8 @@ restart: else result_set_id = "default"; } + found_backend->timestamp(); + // we must search ... BackendSetPtr new_set(new BackendSet(result_set_id, databases, query)); @@ -877,6 +889,8 @@ void yf::SessionShared::Frontend::present(mp::Package &package, bc->release_backend(found_backend); return; } + + found_backend->timestamp(); Z_APDU *p_apdu = zget_APDU(odr, Z_APDU_presentRequest); Z_PresentRequest *p_req = p_apdu->u.presentRequest; @@ -950,6 +964,7 @@ void yf::SessionShared::Frontend::scan(mp::Package &frontend_package, else { Package scan_package(backend->m_session, frontend_package.origin()); + backend->timestamp(); scan_package.copy_filter(frontend_package); scan_package.request() = apdu_req; scan_package.move(); @@ -987,8 +1002,7 @@ void yf::SessionShared::BackendClass::expire_class() { bit++; } - else if ((now >= last_use && now - last_use > m_backend_expiry_ttl) - || (now < last_use)) + else if (now < last_use || now - last_use > m_backend_expiry_ttl) { mp::odr odr; (*bit)->m_close_package->response() = odr.create_close( @@ -1011,7 +1025,7 @@ void yf::SessionShared::Rep::expire() { boost::xtime xt; boost::xtime_get(&xt, boost::TIME_UTC); - xt.sec += 30; + xt.sec += m_session_ttl / 3; boost::thread::sleep(xt); BackendClassMap::const_iterator b_it = m_backend_map.begin(); @@ -1162,7 +1176,8 @@ void yf::SessionShared::process(mp::Package &package) const m_p->release_frontend(package); } -void yf::SessionShared::configure(const xmlNode *ptr, bool test_only) +void yf::SessionShared::configure(const xmlNode *ptr, bool test_only, + const char *path) { for (ptr = ptr->children; ptr; ptr = ptr->next) {