From 60479929dbe76e4d9e16ece32440973259ac5708 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 31 Dec 2007 12:46:04 -0800 Subject: [PATCH] some switchover to sessionmap --- src/Makefile | 1 + src/mds/MDS.cc | 29 +++++----- src/mds/MDS.h | 2 + src/mds/Server.cc | 5 +- src/mds/SessionMap.cc | 129 ++++++++++++++++++++++++++++++++++++++++++ src/mds/SessionMap.h | 39 +++++++++++-- src/mds/mdstypes.h | 5 +- 7 files changed, 185 insertions(+), 25 deletions(-) create mode 100644 src/mds/SessionMap.cc diff --git a/src/Makefile b/src/Makefile index dd4ecac802f3d..7b810121a9d27 100644 --- a/src/Makefile +++ b/src/Makefile @@ -71,6 +71,7 @@ MDS_OBJS= \ mds/LogEvent.o\ mds/IdAllocator.o\ mds/ClientMap.o\ + mds/SessionMap.o\ mds/MDLog.o OSD_OBJS= \ diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 87ea76ba9fb45..28ffc0d755ed9 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -33,7 +33,6 @@ #include "MDBalancer.h" #include "IdAllocator.h" #include "Migrator.h" -//#include "Renamer.h" #include "AnchorTable.h" #include "AnchorClient.h" @@ -72,7 +71,7 @@ // cons/des MDS::MDS(int whoami, Messenger *m, MonMap *mm) : timer(mds_lock), - clientmap(this) { + clientmap(this), sessionmap(this) { this->whoami = whoami; @@ -280,15 +279,15 @@ void MDS::forward_message_mds(Message *req, int mds) void MDS::send_message_client(Message *m, int client) { - version_t seq = clientmap.inc_push_seq(client); + version_t seq = sessionmap.inc_push_seq(client); dout(10) << "send_message_client client" << client << " seq " << seq << " " << *m << dendl; - messenger->send_message(m, clientmap.get_inst(client)); + messenger->send_message(m, sessionmap.get_inst(entity_name_t::CLIENT(client))); } void MDS::send_message_client(Message *m, entity_inst_t clientinst) { - version_t seq = clientmap.inc_push_seq(clientinst.name.num()); - dout(10) << "send_message_client client" << clientinst.name.num() << " seq " << seq << " " << *m << dendl; + version_t seq = sessionmap.inc_push_seq(clientinst.name.num()); + dout(10) << "send_message_client " << clientinst.name << " seq " << seq << " " << *m << dendl; messenger->send_message(m, clientinst); } @@ -654,12 +653,12 @@ void MDS::bcast_mds_map() dout(7) << "bcast_mds_map " << mdsmap->get_epoch() << dendl; // share the map with mounted clients - for (set::const_iterator p = clientmap.get_session_set().begin(); - p != clientmap.get_session_set().end(); - ++p) { - messenger->send_message(new MMDSMap(mdsmap), - clientmap.get_inst(*p)); - } + set clients; + sessionmap.get_session_set(clients); + for (set::const_iterator p = clients.begin(); + p != clients.end(); + ++p) + messenger->send_message(new MMDSMap(mdsmap), sessionmap.get_inst(*p)); last_client_mdsmap_bcast = mdsmap->get_epoch(); } @@ -756,7 +755,7 @@ void MDS::boot_create() idalloc->save(fin->new_sub()); // write empty clientmap - clientmap.save(fin->new_sub()); + sessionmap.save(fin->new_sub()); // fixme: fake out anchortable if (mdsmap->get_anchortable() == whoami) { @@ -793,8 +792,8 @@ void MDS::boot_start(int step) dout(2) << "boot_start " << step << ": opening idalloc" << dendl; idalloc->load(gather->new_sub()); - dout(2) << "boot_start " << step << ": opening clientmap" << dendl; - clientmap.load(gather->new_sub()); + dout(2) << "boot_start " << step << ": opening sessionmap" << dendl; + sessionmap.load(gather->new_sub()); if (mdsmap->get_anchortable() == whoami) { dout(2) << "boot_start " << step << ": opening anchor table" << dendl; diff --git a/src/mds/MDS.h b/src/mds/MDS.h index 400bdb130281e..f0f5316fc6eb6 100644 --- a/src/mds/MDS.h +++ b/src/mds/MDS.h @@ -42,6 +42,7 @@ using namespace __gnu_cxx; #include "MDSMap.h" #include "ClientMap.h" +#include "SessionMap.h" @@ -200,6 +201,7 @@ class MDS : public Dispatcher { // -- client map -- ClientMap clientmap; + SessionMap sessionmap; epoch_t last_client_mdsmap_bcast; //void log_clientmap(Context *c); diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 6241adbde9d79..602f3d2662c96 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -141,11 +141,12 @@ void Server::handle_client_session(MClientSession *m) dout(3) << "handle_client_session " << *m << " from " << m->get_source() << dendl; int from = m->get_source().num(); bool open = false; + Session *session = mds->sessionmap.get_session(m->get_source()); switch (m->op) { - case MClientSession::OP_REQUEST_OPEN; + case MClientSession::OP_REQUEST_OPEN: open = true; - if (mds->clientmap.have_session(from)) { + if (!session) { dout(10) << "already open, dropping this req" << dendl; delete m; return; diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc new file mode 100644 index 0000000000000..6876fb5052044 --- /dev/null +++ b/src/mds/SessionMap.cc @@ -0,0 +1,129 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "MDS.h" +#include "SessionMap.h" +#include "osdc/Filer.h" + +#include "config.h" + +#define dout(x) if (x <= g_conf.debug_mds) *_dout << dbeginl << g_clock.now() << " mds" << mds->get_nodeid() << ".sessionmap " + +void SessionMap::init_inode() +{ + memset(&inode, 0, sizeof(inode)); + inode.ino = MDS_INO_SESSIONMAP_OFFSET + mds->get_nodeid(); + inode.layout = g_OSD_FileLayout; +} + + +// ---------------- +// LOAD + +class C_SM_Load : public Context { + SessionMap *sessionmap; +public: + bufferlist bl; + C_SM_Load(SessionMap *cm) : sessionmap(cm) {} + void finish(int r) { + sessionmap->_load_finish(bl); + } +}; + +void SessionMap::load(Context *onload) +{ + dout(10) << "load" << dendl; + + init_inode(); + + if (onload) + waiting_for_load.push_back(onload); + + C_SM_Load *c = new C_SM_Load(this); + mds->filer->read(inode, + 0, inode.layout.fl_stripe_unit, + &c->bl, + c); + +} + +void SessionMap::_load_finish(bufferlist &bl) +{ + decode(bl); + dout(10) << "_load_finish v " << version + << ", " << session_map.size() << " sessions, " + << bl.length() << " bytes" + << dendl; + projected = committing = committed = version; + finish_contexts(waiting_for_load); +} + + +// ---------------- +// SAVE + +class C_SM_Save : public Context { + SessionMap *sessionmap; + version_t version; +public: + C_SM_Save(SessionMap *cm, version_t v) : sessionmap(cm), version(v) {} + void finish(int r) { + sessionmap->_save_finish(version); + } +}; + +void SessionMap::save(Context *onsave, version_t needv) +{ + dout(10) << "save needv " << needv << ", v " << version << dendl; + + if (needv && committing >= needv) { + assert(committing > committed); + commit_waiters[committing].push_back(onsave); + return; + } + + commit_waiters[version].push_back(onsave); + + bufferlist bl; + + init_inode(); + encode(bl); + committing = version; + mds->filer->write(inode, + 0, bl.length(), bl, + 0, + 0, new C_SM_Save(this, version)); +} + +void SessionMap::_save_finish(version_t v) +{ + dout(10) << "_save_finish v" << v << dendl; + committed = v; + + finish_contexts(commit_waiters[v]); + commit_waiters.erase(v); +} + + +// ------------------- + +void SessionMap::encode(bufferlist& bl) +{ + +} + +void SessionMap::decode(bufferlist& bl) +{ + +} diff --git a/src/mds/SessionMap.h b/src/mds/SessionMap.h index e459d5d15a18e..c4aa9472459b4 100644 --- a/src/mds/SessionMap.h +++ b/src/mds/SessionMap.h @@ -89,6 +89,7 @@ private: MDS *mds; hash_map session_map; version_t version, projected, committing, committed; + map > commit_waiters; public: SessionMap(MDS *m) : mds(m), @@ -102,19 +103,45 @@ public: return &session_map[w]; return 0; } - entity_inst_t& get_inst(entity_name_t w) { - assert(session_map.count(w)); - return session_map[w].inst; - } - Session* add_session(entity_name_t w) { return &session_map[w]; } void remove_session(entity_name_t w) { session_map.erase(w); } + + void get_session_set(set& s) { + for (hash_map::iterator p = session_map.begin(); + p != session_map.end(); + p++) + s.insert(p->first); + } + + // helpers + entity_inst_t& get_inst(entity_name_t w) { + assert(session_map.count(w)); + return session_map[w].inst; + } + version_t inc_push_seq(int client) { + return get_session(entity_name_t::CLIENT(client))->inc_push_seq(); + } + version_t get_push_seq(int client) { + return get_session(entity_name_t::CLIENT(client))->get_push_seq(); + } - + // -- loading, saving -- + inode_t inode; + list waiting_for_load; + + void encode(bufferlist& bl); + void decode(bufferlist& bl); + + void init_inode(); + void load(Context *onload); + void _load_finish(bufferlist &bl); + void save(Context *onsave, version_t needv=0); + void _save_finish(version_t v); + }; diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index bda0b5591ae5f..7ef2164684134 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -36,8 +36,9 @@ using namespace std; #define MDS_INO_LOG_OFFSET (1*MAX_MDS) #define MDS_INO_IDS_OFFSET (2*MAX_MDS) #define MDS_INO_CLIENTMAP_OFFSET (3*MAX_MDS) -#define MDS_INO_STRAY_OFFSET (4*MAX_MDS) -#define MDS_INO_BASE (5*MAX_MDS) +#define MDS_INO_SESSIONMAP_OFFSET (4*MAX_MDS) +#define MDS_INO_STRAY_OFFSET (5*MAX_MDS) +#define MDS_INO_BASE (6*MAX_MDS) #define MDS_INO_STRAY(x) (MDS_INO_STRAY_OFFSET+((unsigned)x)) #define MDS_INO_IS_STRAY(i) ((i) >= MDS_INO_STRAY_OFFSET && (i) < MDS_INO_STRAY_OFFSET+MAX_MDS) -- 2.39.5