]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: fix up osd_auto_weight
authorSage Weil <sage@newdream.net>
Tue, 17 Jun 2008 22:54:03 +0000 (15:54 -0700)
committerSage Weil <sage@newdream.net>
Tue, 17 Jun 2008 22:54:03 +0000 (15:54 -0700)
src/crush/CrushWrapper.h
src/mon/OSDMonitor.cc
src/osd/OSD.cc
src/osd/OSDMap.cc
src/osd/OSDMap.h

index 2e6741beef00da605490f31272361aa700649f79..2a055f06ef1037bdb54f5813bed81290deb10997 100644 (file)
@@ -339,6 +339,21 @@ public:
       out[i] = rawout[i];
   }
 
+
+  void adjust_osd_weights(map<int,double> &weights) {
+    float max = 0;
+    for (map<int,double>::iterator p = weights.begin(); p != weights.end(); p++)
+      if (p->second > max)
+       max = p->second;
+    
+    for (map<int,double>::iterator p = weights.begin(); p != weights.end(); p++) {
+      unsigned w = 0x10000 - (p->second / max * 0x10000);
+      set_offload(p->first, w);
+    }
+  }
+  
+
+
   int read_from_file(const char *fn) {
     bufferlist bl;
     int r = bl.read_file(fn);
index 642e77bca451147ef983f7c9821eb43c09ac6a56..855c78750b96adca5e6af3c8ec77eeb14794ef74 100644 (file)
@@ -318,18 +318,22 @@ bool OSDMonitor::prepare_update(Message *m)
 bool OSDMonitor::should_propose(double& delay)
 {
   dout(10) << "should_propose" << dendl;
-  if (osdmap.epoch == 1) {
-    if (pending_inc.new_up.size() == (unsigned)osdmap.get_max_osd()) {
-      delay = 0.0;
-      if (g_conf.osd_auto_weight) {
-       CrushWrapper crush;
-       OSDMap::build_simple_crush_map(crush, osdmap.get_max_osd(), osd_weight);
-       crush.encode(pending_inc.crush);
-      }
-      return true;
-    } else 
-      return false;
+
+  // adjust osd weights?
+  if (osd_weight.size() == (unsigned)osdmap.get_max_osd()) {
+    dout(0) << " adjusting crush osd weights based on " << osd_weight << dendl;
+    bufferlist bl;
+    osdmap.crush.encode(bl);
+    CrushWrapper crush;
+    bufferlist::iterator p = bl.begin();
+    crush.decode(p);
+    crush.adjust_osd_weights(osd_weight);
+    crush.encode(pending_inc.crush);
+    delay = 0.0;
+    osd_weight.clear();
+    return true;
   }
+
   return PaxosService::should_propose(delay);
 }
 
@@ -518,8 +522,9 @@ bool OSDMonitor::prepare_boot(MOSDBoot *m)
     
     // mark in?
     pending_inc.new_offload[from] = CEPH_OSD_IN;
-    
-    osd_weight[from] = m->sb.weight;
+
+    if (m->sb.weight)
+      osd_weight[from] = m->sb.weight;
 
     // wait
     paxos->wait_for_commit(new C_Booted(this, m));
index 02f8e8405e41cc14b5e6d02fdda595f329482229..1016e417329e94ae0951ca7f5f0cc92b5c8af51d 100644 (file)
@@ -141,6 +141,8 @@ ObjectStore *OSD::create_object_store(const char *dev)
 int OSD::mkfs(const char *dev, ceph_fsid fsid, int whoami)
 {
   ObjectStore *store = create_object_store(dev);
+  if (!store)
+    return -ENOENT;
   int err = store->mkfs();    
   if (err < 0) return err;
   err = store->mount();
@@ -172,6 +174,7 @@ int OSD::mkfs(const char *dev, ceph_fsid fsid, int whoami)
     bufferptr bp(1048576);
     bp.zero();
     bl.push_back(bp);
+    cout << "testing disk bandwidth..." << std::endl;
     utime_t start = g_clock.now();
     for (int i=0; i<1000; i++) 
       store->write(0, pobject_t(0, 0, object_t(999,i)), 0, bl.length(), bl, 0);
index e08f9199775a5a229a81f4a8e3635cf9392e0560..89248f85e1273b38c097cfb92e2275097caac70f 100644 (file)
@@ -32,8 +32,7 @@ void OSDMap::build_simple(epoch_t e, ceph_fsid &fsid,
   pg_num = pgp_num = num_osd << pg_bits;
 
   // crush map
-  map<int,double> weights;
-  build_simple_crush_map(crush, num_osd, weights);
+  build_simple_crush_map(crush, num_osd);
 
   for (int i=0; i<num_osd; i++) {
     set_state(i, CEPH_OSD_EXISTS|CEPH_OSD_CLEAN);
@@ -52,7 +51,7 @@ void OSDMap::build_simple(epoch_t e, ceph_fsid &fsid,
   }
 }
 
-void OSDMap::build_simple_crush_map(CrushWrapper& crush, int num_osd, map<int,double>& weights)
+void OSDMap::build_simple_crush_map(CrushWrapper& crush, int num_osd)
 {
   // new
   crush.create();
@@ -165,3 +164,4 @@ void OSDMap::build_simple_crush_map(CrushWrapper& crush, int num_osd, map<int,do
 
   dout(20) << "crush max_devices " << crush.crush->max_devices << dendl;
 }
+
index 4e2ec8fc6f0bd33557b9924db981b3194e0baf11..71a6b1e45976f3df46c4c9cf754e6ce60170f03c 100644 (file)
@@ -357,11 +357,6 @@ private:
     if (inc.fullmap.length())
       return;
 
-    if (inc.crush.length()) {
-      bufferlist::iterator blp = inc.crush.begin();
-      crush.decode(blp);
-    }
-
     // nope, incremental.
     if (inc.new_flags >= 0)
       flags = inc.new_flags;
@@ -420,6 +415,12 @@ private:
         i != inc.old_pg_swap_primary.end();
         i++)
       pg_swap_primary.erase(*i);
+
+    // do new crush map last (after up/down stuff)
+    if (inc.crush.length()) {
+      bufferlist::iterator blp = inc.crush.begin();
+      crush.decode(blp);
+    }
   }
 
   // serialize, unserialize
@@ -715,7 +716,7 @@ private:
    */
   void build_simple(epoch_t e, ceph_fsid &fsid,
                    int num_osd, int pg_bits, int mds_local_osd);
-  static void build_simple_crush_map(CrushWrapper& crush, int num_osd, map<int,double>& weights);
+  static void build_simple_crush_map(CrushWrapper& crush, int num_osd);
 
 };