masterserver

package
v0.0.0-...-fb2c0b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2023 License: GPL-2.0, GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OK int32 = iota
	ERROR_FILE_NOT_EXISTS
	ERROR_PRIMARY_NOT_EXISTS
	ERROR_FILE_ALREADY_EXISTS
	ERROR_NO_SERVER_AVAILABLE
	ERROR_CHUNKSERVER_ALREADY_EXISTS
	ERROR_FAIL_TO_GENERATE_UNIQUE_TOKEN
	ERROR_FAIL_TO_DELETE
	ERROR_FAIL_TO_CONNECT_TO_CHUNKSERVER
	ERROR_FAIL_TO_CREATE_CHUNK_WHEN_CREATEFILE
	ERROR_FAIL_TO_CREATE_CHUNK_WHEN_APPEND
	ERROR_DEAD_BECOME_ALIVE
	ERROR_READ_WRONG_OFFSET
	ERROR_READ_WRONG_SIZE
)
View Source
const (
	DB_SET = iota
	DB_DELETE
)
View Source
const (
	ChunkSize = uint32(64 * 1024 * 1024)
)

Variables

This section is empty.

Functions

func DeleteChunkHandle

func DeleteChunkHandle(primary string, chunkHandle string) error

helper function: given primary and chunkHandle, call DeleteChunk grpc to delete the chunk

func ErrorCodeToString

func ErrorCodeToString(e int32) string

func GenerateToken

func GenerateToken(length int) (string, error)

Given the length and generate unique token. For e.g. given 16 would generate a string token of length 24.

func NewAppendFileResp

func NewAppendFileResp(errorCode int32, primaryIP []string, chunckHandle []string) *pb.AppendFileResp

func NewAppendResultResp

func NewAppendResultResp() *pb.AppendResultResp

func NewCSRegisterResp

func NewCSRegisterResp(errorCode int32) *pb.CSRegisterResp

func NewCreateResp

func NewCreateResp(errorCode int32) *pb.CreateResp

func NewDeleteStatus

func NewDeleteStatus(errorCode int32) *pb.DeleteStatus

func NewGetLocationResp

func NewGetLocationResp(errorCode int32, chunkInfo []*pb.ChunkServerInfo, start uint32, end uint32) *pb.GetLocationResp

func NewGetTokenResp

func NewGetTokenResp(uniqueToken string) *pb.GetTokenResp

func NewHeartBeatResp

func NewHeartBeatResp(errorCode int32) *pb.HeartBeatResp

Types

type ChunkServerChan

type ChunkServerChan struct {
	// contains filtered or unexported fields
}

type ChunkServerInfo

type ChunkServerInfo struct {
	ChunkHandle []string
	Used        []uint32
	Name        string
}

type ClientInfo

type ClientInfo struct {
	Token string
	UUID  string

	// TODO: Save previous response
	GetTokenResp *pb.GetTokenResp
}

type HandleMetaData

type HandleMetaData struct {
	// unique chunk handle of the chunk
	ChunkHandle string

	// the IP address of Primary chunk server of the chunk
	PrimaryChunkServer string

	// IP address of backup chunk server for this chunk
	BackupAddress []string

	// Already used size in bytes
	Used uint

	FileName string
}

type MasterServer

type MasterServer struct {
	pb.UnimplementedMasterServer

	FileMutex            sync.Mutex
	CSToHandleMutex      sync.Mutex
	ChunkServerLoadMutex sync.Mutex

	// a mapping from File name to A slice of HandleMetaData
	Files map[string][]*HandleMetaData

	// a mapping from chunk handle to HandleMetaData
	HandleToMeta map[string]*HandleMetaData

	// a map from the unique Token(Host:Port) of ChunkServer to its Used (sort on value Used)
	ChunkServerLoad map[string]uint

	// a mapping from ChunkServer to all HandleMetaData it has
	CSToHandle map[string][]*HandleMetaData

	// a map record hearbeat channel
	HeartBeatMap map[string]*ChunkServerChan

	// globally unique server name
	ServerName string

	// base directory to store chunk files
	BasePath string

	HBMutex sync.Mutex

	CSRegisterMutex sync.Mutex

	DB *redis.Client

	AppendFileMutex sync.Mutex
}

func (*MasterServer) AppendFile

func (s *MasterServer) AppendFile(ctx context.Context, appendFileReq *pb.AppendFileReq) (*pb.AppendFileResp, error)

Client <-> Master : AppendFile request, given fileName and append size

func (*MasterServer) AppendResult

func (s *MasterServer) AppendResult(ctx context.Context, appendResultReq *pb.AppendResultReq) (*pb.AppendResultResp, error)

chunk server <-> Master : modify used and load based on append outcome

func (*MasterServer) AppendWorker

func (s *MasterServer) AppendWorker(fileName string, fileSize uint32, primary string, peers []string, chunkHandle string, used uint, result chan int32, wg *sync.WaitGroup)

func (*MasterServer) CSRegister

func (s *MasterServer) CSRegister(ctx context.Context, csRegisterReq *pb.CSRegisterReq) (*pb.CSRegisterResp, error)

chunk server <-> Master : ChunkServer Register, save the chunk server host and port

func (*MasterServer) Create

func (s *MasterServer) Create(ctx context.Context, createReq *pb.CreateReq) (*pb.CreateResp, error)

client -> Master Create file given the FileName

func (*MasterServer) Delete

func (s *MasterServer) Delete(ctx context.Context, deleteReq *pb.DeleteReq) (*pb.DeleteStatus, error)

Client <-> Master : Delete a file given the filename

func (*MasterServer) GenerateHandleToMetaMap

func (s *MasterServer) GenerateHandleToMetaMap() error

GenerateHandleToMetaMap: when master server re-boot from crash, generate the HandleToMeta map from Files map.

func (*MasterServer) GetLocation

func (s *MasterServer) GetLocation(ctx context.Context, getLocationReq *pb.GetLocationReq) (*pb.GetLocationResp, error)

GetLocation return the IP of the Primary chunkserver and chunkID back to client

func (*MasterServer) GetToken

func (s *MasterServer) GetToken(ctx context.Context, getTokenReq *pb.GetTokenReq) (*pb.GetTokenResp, error)

Client <-> Master : Master return a unique token for each client First message client send to master

func (*MasterServer) HeartBeat

func (s *MasterServer) HeartBeat(ctx context.Context, heartBeatReq *pb.HeartBeatPayload) (*pb.HeartBeatResp, error)

func (*MasterServer) PersistMetaData

func (s *MasterServer) PersistMetaData(chunkMetaData *HandleMetaData)

func (*MasterServer) PersistState

func (s *MasterServer) PersistState(filename string, operation int)

type Pair

type Pair struct {
	// contains filtered or unexported fields
}

Pair represents a key-value pair. For sorting the map

type SnapshotTimer

type SnapshotTimer struct {
	DB       *redis.Client
	Interval int
	Srv      *MasterServer
}

func (*SnapshotTimer) Snapshot

func (t *SnapshotTimer) Snapshot()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL