Documentation ¶
Overview ¶
Package server contains core functionality for our cache servers; storing & retrieving files etc.
Index ¶
- func BuildGrpcServer(port int, cache *Cache, cluster *cluster.Cluster, ...) (*grpc.Server, net.Listener)
- func BuildRouter(cache *Cache) *mux.Router
- func ServeGrpcForever(server *grpc.Server, lis net.Listener)
- type Cache
- func (cache *Cache) DeleteAllArtifacts() error
- func (cache *Cache) DeleteArtifact(artPath string) error
- func (cache *Cache) NumFiles() int
- func (cache *Cache) RetrieveArtifact(artPath string) ([]*pb.Artifact, error)
- func (cache *Cache) StoreArtifact(artPath string, key []byte, symlink string) error
- func (cache *Cache) StoreMetadata(artPath, hostname, address, peer string) error
- func (cache *Cache) TotalSize() int64
- type RPCCacheServer
- func (r *RPCCacheServer) Delete(ctx context.Context, req *pb.DeleteRequest) (*pb.DeleteResponse, error)
- func (r *RPCCacheServer) ListNodes(ctx context.Context, req *pb.ListRequest) (*pb.ListResponse, error)
- func (r *RPCCacheServer) Retrieve(ctx context.Context, req *pb.RetrieveRequest) (*pb.RetrieveResponse, error)
- func (r *RPCCacheServer) Store(ctx context.Context, req *pb.StoreRequest) (*pb.StoreResponse, error)
- type RPCServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildGrpcServer ¶
func BuildGrpcServer(port int, cache *Cache, cluster *cluster.Cluster, keyFile, certFile, caCertFile, readonlyKeys, writableKeys string) (*grpc.Server, net.Listener)
BuildGrpcServer creates a new, unstarted grpc.Server and returns it. It also returns a net.Listener to start it on.
func BuildRouter ¶
BuildRouter creates a router, sets the base FileServer directory and the Handler Functions for each endpoint, and then returns the router.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
A Cache is the underlying implementation of our HTTP and RPC caches that handles storing & retrieving artifacts.
func NewCache ¶
func NewCache(path string, cleanFrequency, maxArtifactAge time.Duration, lowWaterMark, highWaterMark uint64) *Cache
NewCache initialises the cache and fires off a background cleaner goroutine which runs every cleanFrequency seconds. The high and low water marks control a (soft) max size and a (harder) minimum size.
func (*Cache) DeleteAllArtifacts ¶
DeleteAllArtifacts will remove all files in the cache directory. The function will return the first error found in the process, or nil if the process is successful.
func (*Cache) DeleteArtifact ¶
DeleteArtifact takes in the artifact path as a parameter and removes the artifact from disk. The function will return the first error found in the process, or nil if the process is successful.
func (*Cache) NumFiles ¶
NumFiles returns the number of files currently monitored by the cache.
func (*Cache) RetrieveArtifact ¶
RetrieveArtifact takes in the artifact path as a parameter and checks in the base server file directory to see if the file exists in the given path. If found, the function will return whatever's been stored there, which might be a directory and therefore contain multiple files to be returned.
func (*Cache) StoreArtifact ¶
StoreArtifact takes in the artifact content and path as parameters and creates a file with the given content in the given path. The function will return the first error found in the process, or nil if the process is successful.
func (*Cache) StoreMetadata ¶
StoreMetadata stores some metadata about the given artifact in a simple format. This mostly just identifies where it came from.
type RPCCacheServer ¶
type RPCCacheServer struct {
// contains filtered or unexported fields
}
A RPCCacheServer implements our RPC cache, including communication in a cluster.
func (*RPCCacheServer) Delete ¶
func (r *RPCCacheServer) Delete(ctx context.Context, req *pb.DeleteRequest) (*pb.DeleteResponse, error)
Delete implements the Delete RPC to delete an artifact from the cache.
func (*RPCCacheServer) ListNodes ¶
func (r *RPCCacheServer) ListNodes(ctx context.Context, req *pb.ListRequest) (*pb.ListResponse, error)
ListNodes implements the RPC for clustered servers.
func (*RPCCacheServer) Retrieve ¶
func (r *RPCCacheServer) Retrieve(ctx context.Context, req *pb.RetrieveRequest) (*pb.RetrieveResponse, error)
Retrieve implements the Retrieve RPC to retrieve artifacts from the cache.
func (*RPCCacheServer) Store ¶
func (r *RPCCacheServer) Store(ctx context.Context, req *pb.StoreRequest) (*pb.StoreResponse, error)
Store implements the Store RPC to store an artifact in the cache.
type RPCServer ¶
type RPCServer struct {
// contains filtered or unexported fields
}
RPCServer implements the gRPC server for communication between cache nodes.
func (*RPCServer) Join ¶
func (r *RPCServer) Join(ctx context.Context, req *pb.JoinRequest) (*pb.JoinResponse, error)
Join implements the Join RPC for a new server joining the cluster.
func (*RPCServer) Replicate ¶
func (r *RPCServer) Replicate(ctx context.Context, req *pb.ReplicateRequest) (*pb.ReplicateResponse, error)
Replicate implements the Replicate RPC for replicating an artifact from another node.