Esempio n. 1
0
func (s *store) StartDisk() error {
	log.Printf("Starting disk server on %v", s.dir)
	disk, err := mdbs.NewMDBServer(s.dir, 0, 0600, server.MDBInitialSize, 2, 10*time.Millisecond, db.DB)
	if err != nil {
		return err
	}
	s.db = disk.(*db.Databases)
	return nil
}
Esempio n. 2
0
func main() {
	log.SetPrefix(common.ProductName + " ")
	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
	log.Println(os.Args)

	procs := runtime.NumCPU()
	if procs < 2 {
		procs = 2
	}
	runtime.GOMAXPROCS(procs)

	var vUUIdStr string
	flag.StringVar(&vUUIdStr, "var", "", "var to interrogate")
	flag.Parse()

	dirs := flag.Args()
	if len(dirs) == 0 {
		log.Fatal("No dirs supplied")
	}

	vars := make(map[common.VarUUId]*varstate)
	for _, d := range dirs {
		dir := d
		log.Printf("...loading from %v\n", dir)
		disk, err := mdbs.NewMDBServer(dir, 0, 0600, server.OneTB, 1, time.Millisecond, db.DB)
		if err != nil {
			log.Println(err)
			continue
		}
		loadVars(disk, vars)
		disk.Shutdown()
	}

	log.Printf("Found %v unique vars", len(vars))

	if vUUIdStr != "" {
		vUUId := common.MakeVarUUIdFromStr(vUUIdStr)
		if vUUId == nil {
			log.Printf("Unable to parse %v as vUUId\n", vUUIdStr)
		}
		if state, found := vars[*vUUId]; found {
			log.Println(state)
		} else {
			log.Printf("Unable to find %v\n", vUUId)
		}
	}
}
Esempio n. 3
0
func (s *server) start() {
	os.Stdin.Close()

	procs := runtime.NumCPU()
	if procs < 2 {
		procs = 2
	}
	runtime.GOMAXPROCS(procs)

	commandLineConfig, err := s.commandLineConfig()
	s.maybeShutdown(err)
	if commandLineConfig == nil {
		commandLineConfig = configuration.BlankTopology("").Configuration
	}

	nodeCertPrivKeyPair, err := certs.GenerateNodeCertificatePrivateKeyPair(s.certificate)
	for idx := range s.certificate {
		s.certificate[idx] = 0
	}
	s.certificate = nil
	s.maybeShutdown(err)

	disk, err := mdbs.NewMDBServer(s.dataDir, 0, 0600, goshawk.MDBInitialSize, procs/2, time.Millisecond, db.DB)
	s.maybeShutdown(err)
	db := disk.(*db.Databases)
	s.addOnShutdown(db.Shutdown)

	cm, transmogrifier := network.NewConnectionManager(s.rmId, s.bootCount, procs, db, nodeCertPrivKeyPair, s.port, s, commandLineConfig)
	s.addOnShutdown(func() { cm.Shutdown(paxos.Sync) })
	s.addOnShutdown(transmogrifier.Shutdown)
	s.connectionManager = cm
	s.transmogrifier = transmogrifier

	go s.signalHandler()

	listener, err := network.NewListener(s.port, cm)
	s.maybeShutdown(err)
	s.addOnShutdown(listener.Shutdown)

	defer s.shutdown(nil)
	<-s.shutdownChan
}
Esempio n. 4
0
func main() {
	log.SetPrefix("MDB Soak Test ")
	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
	log.Println(os.Args)

	procs := runtime.NumCPU()
	if procs < 2 {
		procs = 2
	}
	runtime.GOMAXPROCS(procs)

	var records, readers int
	var rewriter bool

	flag.IntVar(&records, "records", 1000, "Number of records to write to database (default 1000)")
	flag.IntVar(&readers, "readers", 1, "Number of concurrent readers to use (default 1)")
	flag.BoolVar(&rewriter, "rewriter", false, "Run a rewriter concurrently (default false)")
	flag.Parse()

	if records < 1 || readers < 0 {
		log.Fatal("records must be > 0 and readers must be >= 0")
	}

	dir, err := ioutil.TempDir("", "mdb_soak_test")
	if err != nil {
		log.Fatal("Cannot create temporary directory")
	}
	defer os.RemoveAll(dir)
	err = os.MkdirAll(dir, 0770)
	if err != nil {
		log.Fatal("Cannot create directory:", dir)
	}
	log.Println("Using dir", dir)

	dbs := &DBs{
		Test: &mdbs.DBISettings{Flags: mdb.CREATE | mdb.INTEGERKEY},
	}
	server, err := mdbs.NewMDBServer(dir, openFlags, 0600, terabyte, 0, 2*time.Millisecond, dbs)
	if err != nil {
		log.Fatal("Cannot start server:", err)
	}
	defer server.Shutdown()

	popStart := time.Now()
	if err = populate(records, server, dbs); err != nil {
		log.Fatal(err)
	}
	popEnd := time.Now()
	popTime := popEnd.Sub(popStart)
	popRate := float64(int64(records)*time.Second.Nanoseconds()) / float64(popTime.Nanoseconds())
	log.Println("Populating DB with", records, "records took", popTime, "(", popRate, "records/sec )")

	for idx := 0; idx < readers; idx++ {
		go worker(int64(records), server, dbs, readers, idx, false)
	}

	if rewriter {
		go worker(int64(records), server, dbs, 1, -1, true)
	}

	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGTERM, os.Interrupt)
	<-sigs
}
Esempio n. 5
0
func (s *server) start() {
	procs := runtime.NumCPU()
	if procs < 2 {
		procs = 2
	}
	runtime.GOMAXPROCS(procs)

	disk, err := mdbs.NewMDBServer(s.dataDir, mdb.WRITEMAP, 0600, goshawk.OneTB, procs/2, time.Millisecond, db.DB)
	s.maybeShutdown(err)
	s.addOnShutdown(disk.Shutdown)

	cm, lc := network.NewConnectionManager(s.rmId, s.bootCount, procs, disk, s.passwordHash)
	s.connectionManager = cm
	s.addOnShutdown(cm.Shutdown)
	s.addOnShutdown(lc.Shutdown)

	s.Add(1)
	go s.signalHandler()

	topologyLocal, err := network.GetTopologyFromLocalDatabase(cm, cm.Dispatchers.VarDispatcher, lc)
	s.maybeShutdown(err)

	topology, err := s.chooseTopology(topologyLocal)
	s.maybeShutdown(err)

	if topologyLocal == nil {
		topologyTxnId, err := network.CreateTopologyZero(cm, topology, lc)
		s.maybeShutdown(err)
		topology.DBVersion = topologyTxnId
	}

	cm.SetTopology(topology)

	cm.Dispatchers.VarDispatcher.ApplyToVar(func(v *eng.Var, err error) {
		if err != nil {
			log.Println("Error trying to subscribe to topology:", err)
			return
		}
		emptyTxnId := common.MakeTxnId([]byte{})
		v.AddWriteSubscriber(emptyTxnId,
			func(v *eng.Var, value []byte, refs *msgs.VarIdPos_List, txn *eng.Txn) {
				var rootVarPosPtr *msgs.VarIdPos
				if refs.Len() == 1 {
					root := refs.At(0)
					rootVarPosPtr = &root
				}
				topology, err := goshawk.TopologyDeserialize(txn.Id, rootVarPosPtr, value)
				if err != nil {
					log.Println("Unable to deserialize new topology:", err)
				}
				cm.SetTopology(topology)
				disk.WithEnv(func(env *mdb.Env) (interface{}, error) {
					return nil, env.SetFlags(mdb.MAPASYNC, topology.AsyncFlush)
				})
			})
	}, false, goshawk.TopologyVarUUId)

	cm.AddSender(network.NewTopologyWriter(topology, lc, cm))

	localHost, remoteHosts, err := topology.LocalRemoteHosts(s.port)
	s.maybeShutdown(err)

	log.Printf(">==> We are %v (%v) <==<\n", localHost, s.rmId)

	listener, err := network.NewListener(s.port, cm)
	s.maybeShutdown(err)
	s.addOnShutdown(listener.Shutdown)

	cm.SetDesiredServers(localHost, remoteHosts)

	defer s.shutdown(nil)
	s.Wait()
}