Skip to content

Commit

Permalink
logs
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur-x committed Sep 12, 2022
1 parent 80a9040 commit 83c40fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Retain

Retain is a cloud file storage service that lets you sync files across multiple nodes, supporting creation, modification, deletion and fetching specific versions of a file (in progress). Retain is an ongoing extension of the CSE 224 project *Surfstore*.

## Usage
1. Run your server using this:
1. Download and unzip the release. On Linux, run your server using this:
```shell
bin/retainServe -s <service> -p <port> -l -d (BlockStoreAddr*)
bin/retainServe -s <serviceType> -p <port> -l -d (blockStoreAddr*)
```
Here, `service` should be one of three values: meta, block, or both. This is used to specify the service provided by the server. `port` defines the port number that the server listens to (default=8080). `-l` configures the server to only listen on localhost. `-d` configures the server to output log statements. Lastly, (BlockStoreAddr\*) is the BlockStore address that the server is configured with. If `service=both` then the BlockStoreAddr should be the `ip:port` of this server.
Here, `service` should be one of three values: meta, block, or both. This is used to specify the service provided by the server. `port` defines the port number that the server listens to (default=8080). `-l` configures the server to only listen on localhost. `-d` configures the server to output log statements. Lastly, (blockStoreAddr\*) is the BlockStore address that the server is configured with. If `service=both` then the blockStoreAddr should be the `ip:port` of this server.

2. Run your client using this:
```shell
bin/retainSync -d <meta_addr:port> <base_dir> <block_size>
bin/retainSync -d <host:port> <baseDir> <blockSize>
```

### Examples
Expand Down
7 changes: 4 additions & 3 deletions cmd/retainServe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// Usage String
const USAGE_STRING = "./retainServe -s <service_type> -p <port> -l -d (blockStoreAddr*)"
const USAGE_STRING = "./retainServe -s <serviceType> -p <port> -l -d (blockStoreAddr*)"

// Set of valid services
var SERVICE_TYPES = map[string]bool{"meta": true, "block": true, "both": true}
Expand All @@ -31,11 +31,11 @@ func main() {
flag.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(w, " -%s: %v\n", f.Name, f.Usage)
})
fmt.Fprintf(w, " (blockStoreAddr*): BlockStore Address (include self if service type is both)\n")
fmt.Fprintf(w, " (blockStoreAddr*): BlockStore address (include self if service type is both)\n")
}

// Parse command-line argument flags
service := flag.String("s", "", "(required) Service Type of the Server: meta, block, both")
service := flag.String("s", "", "(required) Service type of the Server: meta, block, both")
port := flag.Int("p", 8080, "(default = 8080) Port to accept connections")
localOnly := flag.Bool("l", false, "Only listen on localhost")
debug := flag.Bool("d", false, "Output log statements")
Expand Down Expand Up @@ -89,6 +89,7 @@ func startServer(hostAddr string, serviceType string, blockStoreAddr string) err
if err != nil {
return fmt.Errorf("failed to listen: %v", err)
}
log.Println("Listening on", hostAddr)
if err := grpcServer.Serve(lis); err != nil {
return fmt.Errorf("failed to serve: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/retainSync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const ARG_COUNT int = 3

// Usage strings
const USAGE_STRING = "./retainSync -d host:port baseDir blockSize"
const USAGE_STRING = "./retainSync -d <host:port> <baseDir> <blockSize>"

const DEBUG_NAME = "d"
const DEBUG_USAGE = "Output log statements"
Expand Down
8 changes: 8 additions & 0 deletions src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func download(remoteMetaData *FileMetaData, client RPCClient, blockStoreAddr str
}

func ClientSync(client RPCClient) {
log.Println("Syncing starts!")
var blockStoreAddr string
var Version int32
if err := client.GetBlockStoreAddr(&blockStoreAddr); err != nil {
Expand All @@ -80,11 +81,13 @@ func ClientSync(client RPCClient) {
localMetaData, prs := localFileMetaMap[file.Name()]
newHashes := upload(file, client, blockStoreAddr)
if !prs || len(newHashes) != len(localMetaData.BlockHashList) {
log.Println("Local creation detected:", file.Name())
changed = true
} else {
for i, hash := range newHashes {
if localMetaData.BlockHashList[i] != hash {
changed = true
log.Println("Local modification detected:", file.Name())
break
}
}
Expand All @@ -107,6 +110,7 @@ func ClientSync(client RPCClient) {
}
for filename, localMetaData := range localFileMetaMap {
if _, prs := localFiles[filename]; !prs && (len(localMetaData.BlockHashList) != 1 || localMetaData.BlockHashList[0] != "0") {
log.Println("Local deletion detected:", filename)
newMetaData := FileMetaData{Filename: filename, BlockHashList: []string{"0"}}
newMetaData.Version = localMetaData.Version + 1
if err = client.UpdateFile(&newMetaData, &Version); err != nil {
Expand All @@ -117,15 +121,19 @@ func ClientSync(client RPCClient) {
}
}
}
log.Println("All local changes synced")
remoteFileMetaMap := make(map[string]*FileMetaData)
if err := client.GetFileInfoMap(&remoteFileMetaMap); err != nil {
log.Panicln(err)
}
for filename, remoteMetaData := range remoteFileMetaMap {
if localMetaData, prs := localFileMetaMap[filename]; !prs || localMetaData.Version < remoteMetaData.Version {
log.Println("Newer cloud version detected:", filename)
localFileMetaMap[filename] = remoteMetaData
download(remoteMetaData, client, blockStoreAddr)
}
}
log.Println("All cloud changes synced")
WriteMetaFile(localFileMetaMap, client.BaseDir)
log.Println("Great, job done!")
}

0 comments on commit 83c40fe

Please sign in to comment.