[ARVADOS] updated: 7b223f5209150fe125f611a8e218e5fbbf8a73ee

git at public.curoverse.com git at public.curoverse.com
Tue Nov 17 10:26:47 EST 2015


Summary of changes:
 services/datamanager/collection/collection.go | 12 +++---
 services/datamanager/datamanager.go           |  9 ++++-
 services/datamanager/datamanager_test.go      | 55 +++++++++++++++++++++++++++
 services/datamanager/summary/file.go          | 22 +++++------
 4 files changed, 80 insertions(+), 18 deletions(-)

       via  7b223f5209150fe125f611a8e218e5fbbf8a73ee (commit)
      from  c5602bf4ba4724376c2d5405302d240daaae506f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 7b223f5209150fe125f611a8e218e5fbbf8a73ee
Author: radhika <radhika at curoverse.com>
Date:   Tue Nov 17 10:26:09 2015 -0500

    7490: added couple more datamanager tests with errors injected during GetCollections

diff --git a/services/datamanager/collection/collection.go b/services/datamanager/collection/collection.go
index 55b0b37..463c847 100644
--- a/services/datamanager/collection/collection.go
+++ b/services/datamanager/collection/collection.go
@@ -18,7 +18,7 @@ import (
 )
 
 var (
-	heapProfileFilename string
+	HeapProfileFilename string
 	// globals for debugging
 	totalManifestSize uint64
 	maxManifestSize   uint64
@@ -67,7 +67,7 @@ type SdkCollectionList struct {
 }
 
 func init() {
-	flag.StringVar(&heapProfileFilename,
+	flag.StringVar(&HeapProfileFilename,
 		"heap-profile",
 		"",
 		"File to write the heap profiles to. Leave blank to skip profiling.")
@@ -80,8 +80,8 @@ func init() {
 // Otherwise we would see cumulative numbers as explained here:
 // https://groups.google.com/d/msg/golang-nuts/ZyHciRglQYc/2nh4Ndu2fZcJ
 func WriteHeapProfile() error {
-	if heapProfileFilename != "" {
-		heapProfile, err := os.Create(heapProfileFilename)
+	if HeapProfileFilename != "" {
+		heapProfile, err := os.Create(HeapProfileFilename)
 		if err != nil {
 			return err
 		}
@@ -100,6 +100,8 @@ func GetCollectionsAndSummarize(arvLogger *logger.Logger, params GetCollectionsP
 	results, err := GetCollections(params)
 	if err != nil {
 		loggerutil.LogErrorMessage(arvLogger, fmt.Sprintf("Error during GetCollections with params %v: %v", params, err))
+		results = ReadCollections{}
+		return
 	}
 
 	results.Summarize(params.Logger)
@@ -232,7 +234,7 @@ func GetCollections(params GetCollectionsParams) (results ReadCollections, err e
 	}
 
 	// Write the heap profile for examining memory usage
-	WriteHeapProfile()
+	err = WriteHeapProfile()
 
 	return
 }
diff --git a/services/datamanager/datamanager.go b/services/datamanager/datamanager.go
index a19d01f..e7d22b8 100644
--- a/services/datamanager/datamanager.go
+++ b/services/datamanager/datamanager.go
@@ -107,7 +107,14 @@ func singlerun(arv arvadosclient.ArvadosClient) error {
 
 	dataFetcher(arvLogger, &readCollections, &keepServerInfo)
 
-	summary.MaybeWriteData(arvLogger, readCollections, keepServerInfo)
+	if len(readCollections.UUIDToCollection) == 0 {
+		return nil // no collections read so no more work to do?
+	}
+
+	_, err = summary.MaybeWriteData(arvLogger, readCollections, keepServerInfo)
+	if err != nil {
+		return err
+	}
 
 	buckets := summary.BucketReplication(readCollections, keepServerInfo)
 	bucketCounts := buckets.Counts()
diff --git a/services/datamanager/datamanager_test.go b/services/datamanager/datamanager_test.go
index 26a2fbf..6e5a4df 100644
--- a/services/datamanager/datamanager_test.go
+++ b/services/datamanager/datamanager_test.go
@@ -6,6 +6,8 @@ import (
 	"git.curoverse.com/arvados.git/sdk/go/arvadosclient"
 	"git.curoverse.com/arvados.git/sdk/go/arvadostest"
 	"git.curoverse.com/arvados.git/sdk/go/keepclient"
+	"git.curoverse.com/arvados.git/services/datamanager/collection"
+	"git.curoverse.com/arvados.git/services/datamanager/summary"
 	"io/ioutil"
 	"net/http"
 	"os"
@@ -526,3 +528,56 @@ func TestRunDatamanagerAsNonAdminUser(t *testing.T) {
 		t.Fatalf("Expected error during singlerun as non-admin user")
 	}
 }
+
+func TestPutAndGetBlocks_NoErrorDuringSingleRun(t *testing.T) {
+	testOldBlocksNotDeletedOnDataManagerError(t, "", "", false, false)
+}
+
+func TestPutAndGetBlocks_ErrorDuringGetCollectionsBadWriteTo(t *testing.T) {
+	testOldBlocksNotDeletedOnDataManagerError(t, "/badwritetofile", "", true, true)
+}
+
+func TestPutAndGetBlocks_ErrorDuringGetCollectionsBadHeapProfileFilename(t *testing.T) {
+	testOldBlocksNotDeletedOnDataManagerError(t, "", "/badheapprofilefile", false, true)
+}
+
+/*
+  Create some blocks and backdate some of them.
+  Run datamanager while producing an error condition.
+  Verify that the blocks are hence not deleted.
+*/
+func testOldBlocksNotDeletedOnDataManagerError(t *testing.T, writeDataTo string, heapProfileFile string, expectError bool, expectOldBlocks bool) {
+	defer TearDownDataManagerTest(t)
+	SetupDataManagerTest(t)
+
+	// Put some blocks and backdate them.
+	var oldUnusedBlockLocators []string
+	oldUnusedBlockData := "this block will have older mtime"
+	for i := 0; i < 5; i++ {
+		oldUnusedBlockLocators = append(oldUnusedBlockLocators, putBlock(t, fmt.Sprintf("%s%d", oldUnusedBlockData, i)))
+	}
+	backdateBlocks(t, oldUnusedBlockLocators)
+
+	// Run data manager
+	summary.WriteDataTo = writeDataTo
+	collection.HeapProfileFilename = heapProfileFile
+
+	err := singlerun(arv)
+	if !expectError {
+		if err != nil {
+			t.Fatalf("Got an error during datamanager singlerun: %v", err)
+		}
+	} else {
+		if err == nil {
+			t.Fatalf("Expected error during datamanager singlerun")
+		}
+	}
+	waitUntilQueuesFinishWork(t)
+
+	// Get block indexes and verify that all backdated blocks are not/deleted as expected
+	if expectOldBlocks {
+		verifyBlocks(t, nil, oldUnusedBlockLocators, 2)
+	} else {
+		verifyBlocks(t, oldUnusedBlockLocators, nil, 2)
+	}
+}
diff --git a/services/datamanager/summary/file.go b/services/datamanager/summary/file.go
index 18b3aec..7ed9765 100644
--- a/services/datamanager/summary/file.go
+++ b/services/datamanager/summary/file.go
@@ -22,7 +22,7 @@ type serializedData struct {
 }
 
 var (
-	writeDataTo  string
+	WriteDataTo  string
 	readDataFrom string
 )
 
@@ -32,7 +32,7 @@ type DataFetcher func(arvLogger *logger.Logger,
 	keepServerInfo *keep.ReadServers)
 
 func init() {
-	flag.StringVar(&writeDataTo,
+	flag.StringVar(&WriteDataTo,
 		"write-data-to",
 		"",
 		"Write summary of data received to this file. Used for development only.")
@@ -51,14 +51,13 @@ func init() {
 // working with stale data.
 func MaybeWriteData(arvLogger *logger.Logger,
 	readCollections collection.ReadCollections,
-	keepServerInfo keep.ReadServers) bool {
-	if writeDataTo == "" {
-		return false
+	keepServerInfo keep.ReadServers) (bool, error) {
+	if WriteDataTo == "" {
+		return false, nil
 	}
-	summaryFile, err := os.Create(writeDataTo)
+	summaryFile, err := os.Create(WriteDataTo)
 	if err != nil {
-		loggerutil.FatalWithMessage(arvLogger,
-			fmt.Sprintf("Failed to open %s: %v", writeDataTo, err))
+		return false, err
 	}
 	defer summaryFile.Close()
 
@@ -68,11 +67,10 @@ func MaybeWriteData(arvLogger *logger.Logger,
 		KeepServerInfo:  keepServerInfo}
 	err = enc.Encode(data)
 	if err != nil {
-		loggerutil.FatalWithMessage(arvLogger,
-			fmt.Sprintf("Failed to write summary data: %v", err))
+		return false, err
 	}
-	log.Printf("Wrote summary data to: %s", writeDataTo)
-	return true
+	log.Printf("Wrote summary data to: %s", WriteDataTo)
+	return true, nil
 }
 
 // ShouldReadData should not be used outside of development

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list