Пример #1
0
// NewClient instantiates a Client. The ID string is used for
// identifying the client in remote logs.
func NewClient(c io.ReadWriteCloser, id string) *Client {
	return &Client{
		client:  rpc.NewClient(c),
		id:      id,
		timings: stats.NewTimerStats(),
	}
}
Пример #2
0
// NewStore creates a content cache based in directory d.
// memorySize sets the maximum number of file contents to keep in
// memory.
func NewStore(options *StoreOptions) *Store {
	if options.Hash == 0 {
		options.Hash = crypto.MD5
	}
	if fi, _ := os.Lstat(options.Dir); fi == nil {
		err := os.MkdirAll(options.Dir, 0700)
		if err != nil {
			panic(err)
		}
	}

	log.Println("reading hex database", options.Dir)
	db := ReadHexDatabase(options.Dir)
	log.Println("done reading.")

	c := &Store{
		Options:  options,
		have:     db,
		faulting: make(map[string]bool),
		timings:  stats.NewTimerStats(),
	}
	c.initThroughputSampler()
	if options.MemCount > 0 {
		c.inMemoryCache = NewLruCache(options.MemCount)
		if options.MemMaxSize == 0 {
			options.MemMaxSize = 64 * 1024
		}
	}

	c.cond = sync.NewCond(&c.mutex)
	return c
}
Пример #3
0
func NewFsServer(a *attr.AttributeCache, cache *cba.Store) *FsServer {
	me := &FsServer{
		content:    cache,
		attributes: a,
		stats:      stats.NewTimerStats(),
	}

	return me
}
Пример #4
0
// NewServer instantiates an RPC server for the given
// AttributeCache. If timings is optional and will be used for
// recording timing data.
func NewServer(a *AttributeCache, timings *stats.TimerStats) *Server {
	if timings == nil {
		timings = stats.NewTimerStats()
	}
	me := &Server{
		attributes: a,
		stats:      timings,
	}

	return me
}
Пример #5
0
func NewRpcFs(attrClient *attr.Client, cache *cba.Store, contentConn io.ReadWriteCloser) *RpcFs {
	fs := &RpcFs{
		FileSystem:    pathfs.NewDefaultFileSystem(),
		attrClient:    attrClient,
		contentClient: cache.NewClient(contentConn),
		timings:       stats.NewTimerStats(),
	}

	fs.attr = attr.NewAttributeCache(
		func(n string) *attr.FileAttr {
			a := attr.FileAttr{}
			err := attrClient.GetAttr(n, &a)
			if err != nil {
				log.Printf("GetAttr %s: %v", n, err)
				return nil
			}
			return &a
		}, nil)
	fs.cache = cache
	return fs
}