[complement-svn] SF.net SVN: complement: [1744] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-09-25 14:25:18
|
Revision: 1744 http://complement.svn.sourceforge.net/complement/?rev=1744&view=rev Author: complement Date: 2007-09-25 07:25:16 -0700 (Tue, 25 Sep 2007) Log Message: ----------- try to connect to well-known hosts and/or become a server to establish virtual synchrony net; libjanus: version 0.4.0 Modified Paths: -------------- trunk/complement/explore/include/janus/vshostmgr.h trunk/complement/explore/lib/janus/ChangeLog trunk/complement/explore/lib/janus/Makefile trunk/complement/explore/lib/janus/Makefile.inc trunk/complement/explore/lib/janus/ut/unit_test.cc trunk/complement/explore/lib/janus/ut/vt_operations.h trunk/complement/explore/lib/janus/ut/vt_remote.cc trunk/complement/explore/lib/janus/vshostmgr.cc Modified: trunk/complement/explore/include/janus/vshostmgr.h =================================================================== --- trunk/complement/explore/include/janus/vshostmgr.h 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/include/janus/vshostmgr.h 2007-09-25 14:25:16 UTC (rev 1744) @@ -39,12 +39,15 @@ // typedef std::list<stem::gaddr_type> vshost_container_t; #if defined(__USE_STLPORT_TR1) || defined(__USE_STD_TR1) typedef std::tr1::unordered_set<stem::gaddr_type> vshost_container_t; + typedef std::tr1::unordered_set<std::string> vs_wellknown_hosts_container_t; #endif #ifdef __USE_STD_HASH typedef __gnu_cxx::hash_set<stem::gaddr_type> vshost_container_t; + typedef __gnu_cxx::hash_set<std::string> vs_wellknown_hosts_container_t; #endif #ifdef __USE_STLPORT_HASH typedef std::hash_set<stem::gaddr_type> vshost_container_t; + typedef std::hash_set<std::string> vs_wellknown_hosts_container_t; #endif public: @@ -60,9 +63,15 @@ void VSOutMember( const stem::Event_base<VSsync_rq>& ); void VSsync_time( const stem::Event_base<VSsync>& ev ); - void connect( const char *, int ); - void serve( int ); + static void add_wellknown( const char *nm ); + static void add_wellknown( const std::string& nm ); + static void rm_wellknown( const char *nm ); + static void rm_wellknown( const std::string& nm ); + static void add_srvport( int ); + int connect( const char *, int ); + int serve( int ); + size_type vs_known_processes() const { xmt::recursive_scoped_lock lk( this->_theHistory_lock ); @@ -102,6 +111,10 @@ Finalizer finalizer; + static xmt::mutex _wknh_lock; + static vs_wellknown_hosts_container_t _wknhosts; + static int _srvport; + // DECLARE_RESPONSE_TABLE( VSHostMgr, janus::VTHandler ); }; Modified: trunk/complement/explore/lib/janus/ChangeLog =================================================================== --- trunk/complement/explore/lib/janus/ChangeLog 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ChangeLog 2007-09-25 14:25:16 UTC (rev 1744) @@ -1,3 +1,15 @@ +2007-09-25 Petr Ovtchenkov <pt...@is...> + + * vshostmgr.h, vshostmgr.cc: try to connect to well-known hosts + and/or become a server to establish virtual synchrony net; + + * ut/unit_test.cc: test for well-known hosts [nodes of virtual + synchrony net]; + + * lib/janus/ut/vt_operations.h, lib/janus/ut/vt_remote.cc: ditto; + + * libjanus: version 0.4.0. + 2007-08-27 Petr Ovtchenkov <pt...@is...> * janus.h, janus.cc: hide methods, intended for internal Modified: trunk/complement/explore/lib/janus/Makefile =================================================================== --- trunk/complement/explore/lib/janus/Makefile 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/Makefile 2007-09-25 14:25:16 UTC (rev 1744) @@ -21,11 +21,11 @@ dbg-shared : LDLIBS = -lxmtg -lsockiosg -lstemg check: all-shared - $(MAKE) -C test - (cd test; ${OUTPUT_DIR}/ut_vtime) || exit 1 - (cd test; ${OUTPUT_DIR_DBG}/ut_vtime) || exit 1 + $(MAKE) -C ut + (cd ut; ${OUTPUT_DIR}/ut_vtime) || exit 1 + (cd ut; ${OUTPUT_DIR_DBG}/ut_vtime) || exit 1 ifndef WITHOUT_STLPORT - (cd test; ${OUTPUT_DIR_STLDBG}/ut_vt) || exit 1 + (cd ut; ${OUTPUT_DIR_STLDBG}/ut_vt) || exit 1 endif check-release-shared: release-shared @@ -43,7 +43,7 @@ endif depend:: - $(MAKE) -C test depend + $(MAKE) -C ut depend # dbg-shared: DEFS += -DDEBUG Modified: trunk/complement/explore/lib/janus/Makefile.inc =================================================================== --- trunk/complement/explore/lib/janus/Makefile.inc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/Makefile.inc 2007-09-25 14:25:16 UTC (rev 1744) @@ -2,6 +2,6 @@ LIBNAME = janus MAJOR = 0 -MINOR = 3 +MINOR = 4 PATCH = 0 SRC_CC = vtime.cc janus.cc vshostmgr.cc Modified: trunk/complement/explore/lib/janus/ut/unit_test.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/unit_test.cc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ut/unit_test.cc 2007-09-25 14:25:16 UTC (rev 1744) @@ -8,7 +8,7 @@ { using namespace janus; - exam::test_suite::test_case_type tc[3]; + exam::test_suite::test_case_type tc[4]; exam::test_suite t( "virtual time operations" ); @@ -23,7 +23,7 @@ tc[2] = t.add( &vtime_operations::gvt_add, vt_oper, "Group VT add", tc[1] ) ); t.add( &vtime_operations::mgroups, vt_oper, "mgroups", - t.add( &vtime_operations::remote, vt_oper, "remote", + tc[3] = t.add( &vtime_operations::remote, vt_oper, "remote", t.add( &vtime_operations::VTEntryIntoGroup3, vt_oper, "VTEntryIntoGroup3", t.add( &vtime_operations::VTEntryIntoGroup2, vt_oper, "VTEntryIntoGroup2", t.add( &vtime_operations::VTEntryIntoGroup, vt_oper, "VTEntryIntoGroup", @@ -34,6 +34,8 @@ t.add( &vtime_operations::VTDispatch1, vt_oper, "VTDispatch1", t.add( &vtime_operations::vt_object, vt_oper, "VT order", tc[2] )))))))))) ); + t.add( &vtime_operations::wellknownhost, vt_oper, "well-known host", tc[3] ); + return t.girdle(); } Modified: trunk/complement/explore/lib/janus/ut/vt_operations.h =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ut/vt_operations.h 2007-09-25 14:25:16 UTC (rev 1744) @@ -33,6 +33,7 @@ int EXAM_DECL(remote); int EXAM_DECL(mgroups); + int EXAM_DECL(wellknownhost); }; } // namespace janus Modified: trunk/complement/explore/lib/janus/ut/vt_remote.cc =================================================================== --- trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/ut/vt_remote.cc 2007-09-25 14:25:16 UTC (rev 1744) @@ -430,4 +430,92 @@ return EXAM_RESULT; } +int EXAM_IMPL(vtime_operations::wellknownhost) +{ + const char fname[] = "/tmp/yanus_test.shm"; + xmt::shm_alloc<0> seg; + xmt::allocator_shm<xmt::__condition<true>,0> shm_cnd; + xmt::allocator_shm<xmt::__barrier<true>,0> shm_b; + + try { + seg.allocate( fname, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0600 ); + xmt::__barrier<true>& b = *new ( shm_b.allocate( 1 ) ) xmt::__barrier<true>(); + + VSHostMgr::add_wellknown( "localhost:6980" ); + VSHostMgr::add_srvport( 6980 ); + + try { + xmt::fork(); + + long res_flag = 0; + + b.wait(); + + { + YaRemote obj1( "obj client" ); + + obj1.JoinGroup( janus::vs_base::first_user_group ); + + obj1.wait_greeting(); + } + + exit( res_flag ); + } + catch ( xmt::fork_in_parent& child ) { + YaRemote obj1( "obj srv" ); + + // obj1.vtdispatcher()->settrf( janus::Janus::tracenet | janus::Janus::tracedispatch | janus::Janus::tracefault | janus::Janus::tracedelayed | janus::Janus::tracegroup ); + // obj1.vtdispatcher()->settrs( &std::cerr ); + + // obj1.vtdispatcher()->serve( 6980 ); + + obj1.JoinGroup( janus::vs_base::first_user_group ); + + b.wait(); + + // while ( obj1.vtdispatcher()->vs_known_processes() < 2 ) { + // xmt::delay( xmt::timespec( 0, 1000000 ) ); + // } + + obj1.wait_greeting(); + + stem::Event ev( VS_DUMMY_MESS ); + ev.dest( janus::vs_base::first_user_group ); + ev.value() = "hello"; + + obj1.JaSend( ev ); + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 2 ); + EXAM_CHECK( obj1.count == 1 ); + + // obj1.manager()->settrf( stem::EvManager::tracenet | stem::EvManager::tracedispatch ); + // obj1.manager()->settrs( &std::cerr ); + + int stat = -1; + EXAM_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + if ( WIFEXITED(stat) ) { + EXAM_CHECK( WEXITSTATUS(stat) == 0 ); + } else { + EXAM_ERROR( "child interrupted" ); + } + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::first_user_group) == 1 ); + + EXAM_CHECK( obj1.vtdispatcher()->group_size(janus::vs_base::vshosts_group) == 1 ); + // cerr << obj1.vtdispatcher()->vs_known_processes() << endl; + } + + (&b)->~__barrier<true>(); + shm_b.deallocate( &b, 1 ); + } + catch ( const xmt::shm_bad_alloc& err ) { + EXAM_ERROR( err.what() ); + } + + seg.deallocate(); + unlink( fname ); + + return EXAM_RESULT; +} + } // namespace janus Modified: trunk/complement/explore/lib/janus/vshostmgr.cc =================================================================== --- trunk/complement/explore/lib/janus/vshostmgr.cc 2007-09-24 19:06:03 UTC (rev 1743) +++ trunk/complement/explore/lib/janus/vshostmgr.cc 2007-09-25 14:25:16 UTC (rev 1744) @@ -48,6 +48,30 @@ vshost.insert( gaddr_type( stem::janus_addr ) ); JoinGroup( vshosts_group ); + + bool is_connected = false; + + xmt::scoped_lock lk( _wknh_lock ); + for ( vs_wellknown_hosts_container_t::const_iterator i = _wknhosts.begin(); i != _wknhosts.end(); ++i ) { + string s( *i ); + string::size_type p = s.find( ':' ); + if ( p != string::npos ) { + s.replace( p, 1, 1, ' ' ); + stringstream ss( s ); + int port = 0; + ss >> s >> port; + if ( !ss.fail() ) { + if ( connect( s.c_str(), port ) != 0 ) { + continue; + } + is_connected = true; + break; + } + } + } + if ( !is_connected && _srvport != 0 ) { + serve( _srvport ); + } } VSHostMgr::~VSHostMgr() @@ -141,12 +165,19 @@ VTHandler::VSsync_time(ev); } -void VSHostMgr::connect( const char *host, int port ) +int VSHostMgr::connect( const char *host, int port ) { - _clients.push_back( new NetTransportMgr() ); + NetTransportMgr *mgr = new NetTransportMgr(); - addr_type zero = _clients.back()->open( host, port ); + addr_type zero = mgr->open( host, port ); + if ( zero == stem::badaddr ) { + delete mgr; + return -1; + } + + _clients.push_back( mgr ); + gaddr_type ga = manager()->reflect( zero ); if ( ga != gaddr_type() ) { ga.addr = stem::janus_addr; @@ -171,6 +202,7 @@ catch ( ... ) { } #endif // __FIT_VS_TRACE + return 0; } #ifdef __FIT_VS_TRACE else { @@ -184,27 +216,40 @@ } } #endif // __FIT_VS_TRACE + + delete _clients.back(); + _clients.pop_back(); + return -2; } -void VSHostMgr::serve( int port ) +int VSHostMgr::serve( int port ) { - _servers.push_back( new sockmgr_stream_MP<NetTransport>( port ) ); + sockmgr_stream_MP<NetTransport> *mgr = new sockmgr_stream_MP<NetTransport>( port ); + #ifdef __FIT_VS_TRACE try { scoped_lock lk(vtdispatcher()->_lock_tr); if ( vtdispatcher()->_trs != 0 && vtdispatcher()->_trs->good() && (vtdispatcher()->_trflags & Janus::tracenet) ) { *vtdispatcher()->_trs << "serve " << port - << (_servers.back()->good() ? " ok" : " fail" ) - << endl; + << (mgr->good() ? " ok" : " fail" ) << endl; } } catch ( ... ) { } #endif // __FIT_VS_TRACE + if ( !mgr->good() ) { + delete mgr; + return -2; + } + _servers.push_back( mgr ); + return 0; } void VSHostMgr::Subscribe( stem::addr_type addr, group_type grp ) { + if ( vshost.empty() ) { + return; + } try { manager()->transport( addr ); } @@ -226,16 +271,56 @@ *vtdispatcher()->_trs << " -> VS_NEW_REMOTE_MEMBER G" << grp << " " << hex << showbase << ev.src() << " -> " << ev.dest() << dec << endl; - } - } - catch ( ... ) { - } + } + } + catch ( ... ) { + } #endif // __FIT_VS_TRACE } } } } +xmt::mutex VSHostMgr::_wknh_lock; +VSHostMgr::vs_wellknown_hosts_container_t VSHostMgr::_wknhosts; +int VSHostMgr::_srvport = 0; + +void VSHostMgr::add_wellknown( const char *nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + _wknhosts.insert( string(nm) ); +} + +void VSHostMgr::add_wellknown( const std::string& nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + _wknhosts.insert( nm ); +} + +void VSHostMgr::rm_wellknown( const char *nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + vs_wellknown_hosts_container_t::iterator i = _wknhosts.find( string(nm) ); + if ( i != _wknhosts.end() ) { + _wknhosts.erase( i ); + } +} + +void VSHostMgr::rm_wellknown( const std::string& nm ) +{ + xmt::scoped_lock lk( _wknh_lock ); + vs_wellknown_hosts_container_t::iterator i = _wknhosts.find( nm ); + if ( i != _wknhosts.end() ) { + _wknhosts.erase( i ); + } +} + +void VSHostMgr::add_srvport( int p ) +{ + xmt::scoped_lock lk( _wknh_lock ); + _srvport = p; +} + // DEFINE_RESPONSE_TABLE( VSHostMgr ) // EV_Event_base_T_( ST_NULL, VS_NEW_REMOTE_MEMBER, VSNewRemoteMemberDirect, VSsync_rq ) // EV_Event_base_T_( ST_NULL, VS_NEW_MEMBER_RV, VSNewRemoteMemberRevert, VSsync_rq ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |