Merge pull request #375 from harshavardhana/pr_out_golint_fixes

This commit is contained in:
Harshavardhana 2015-03-25 13:25:38 -07:00
commit fab6892bc3
9 changed files with 92 additions and 36 deletions

2
Godeps/Godeps.json generated
View File

@ -20,7 +20,7 @@
},
{
"ImportPath": "github.com/minio-io/iodine",
"Rev": "b279ca8ea714fabc969883a4d1612a4e93d01611"
"Rev": "f92ca01c8671d9565c7aa58e3427364c5e187ccf"
},
{
"ImportPath": "gopkg.in/check.v1",

View File

@ -1,5 +1,5 @@
/*
* Iodine, (C) 2014 Minio, Inc.
* Iodine, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,8 +21,10 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"runtime"
"strconv"
"strings"
"sync"
)
@ -43,25 +45,30 @@ type StackEntry struct {
Data map[string]string
}
var gopath string
var globalState = struct {
sync.RWMutex
m map[string]string
}{m: make(map[string]string)}
// SetGlobalState - set global state
func SetGlobalState(key, value string) {
globalState.Lock()
globalState.m[key] = value
globalState.Unlock()
}
// ClearGlobalState - clear info in globalState struct
func ClearGlobalState() {
globalState.Lock()
for k, _ := range globalState.m {
for k := range globalState.m {
delete(globalState.m, k)
}
globalState.Unlock()
}
// GetGlobalState - get map from globalState struct
func GetGlobalState() map[string]string {
result := make(map[string]string)
globalState.RLock()
@ -72,7 +79,16 @@ func GetGlobalState() map[string]string {
return result
}
// Wrap an error, turning it into an iodine error.
// GetGlobalStateKey - get value for key from globalState struct
func GetGlobalStateKey(k string) string {
result, ok := globalState.m[k]
if !ok {
return ""
}
return result
}
// New - instantiate an error, turning it into an iodine error.
// Adds an initial stack trace.
func New(err error, data map[string]string) *Error {
entry := createStackEntry()
@ -86,18 +102,46 @@ func New(err error, data map[string]string) *Error {
}
}
// createStackEntry - create stack entries
func createStackEntry() StackEntry {
host, _ := os.Hostname()
_, file, line, _ := runtime.Caller(2)
file = strings.TrimPrefix(file, gopath) // trim gopath from file
data := GetGlobalState()
for k, v := range getSystemData() {
data[k] = v
}
entry := StackEntry{
Host: host,
File: file,
Line: line,
Data: GetGlobalState(),
Data: data,
}
return entry
}
func getSystemData() map[string]string {
host, err := os.Hostname()
if err != nil {
host = ""
}
memstats := &runtime.MemStats{}
runtime.ReadMemStats(memstats)
return map[string]string{
"sys.host": host,
"sys.os": runtime.GOOS,
"sys.arch": runtime.GOARCH,
"sys.go": runtime.Version(),
"sys.cpus": strconv.Itoa(runtime.NumCPU()),
"sys.mem.used": strconv.FormatUint(memstats.Alloc, 10),
"sys.mem.allocated": strconv.FormatUint(memstats.TotalAlloc, 10),
"sys.mem.heap.used": strconv.FormatUint(memstats.HeapAlloc, 10),
"sys.mem.heap.allocated": strconv.FormatUint(memstats.HeapSys, 10),
}
}
// Annotate an error with a stack entry and returns itself
func (err *Error) Annotate(info map[string]string) *Error {
entry := createStackEntry()
@ -127,3 +171,11 @@ func (err Error) EmitHumanReadable() string {
func (err Error) Error() string {
return err.EmbeddedError.Error()
}
func init() {
_, iodineFile, _, _ := runtime.Caller(0)
iodineFile = path.Dir(iodineFile) // trim iodine.go
iodineFile = path.Dir(iodineFile) // trim iodine
iodineFile = path.Dir(iodineFile) // trim minio-io
gopath = path.Dir(iodineFile) + "/" // trim github.com
}

View File

@ -1,5 +1,5 @@
/*
* Iodine, (C) 2014 Minio, Inc.
* Iodine, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import (
"bytes"
"encoding/json"
"errors"
"log"
"testing"
)
@ -38,16 +37,16 @@ func TestIodine(t *testing.T) {
}
var prettyBuffer bytes.Buffer
json.Indent(&prettyBuffer, jsonResult, "", " ")
if prettyBuffer.String() == "" {
t.Fail()
}
}
func TestState(t *testing.T) {
SetGlobalState("hello", "world")
state := GetGlobalState()
if res, ok := state["hello"]; ok {
if res != "world" {
t.Error("global state not set: hello->world")
}
} else {
result := GetGlobalStateKey("hello")
if result != "world" {
t.Error("global state not set: hello->world")
t.Fail()
}
ClearGlobalState()
@ -85,7 +84,6 @@ func TestState(t *testing.T) {
}
} else {
err.Annotate(nil)
log.Println(err.EmitHumanReadable())
t.Error("foo2 should be set")
}
}

View File

@ -24,32 +24,32 @@ import (
)
// Integer to Int conversion
func int2CInt(src_err_list []int) *C.int32_t {
var sizeErrInt = int(unsafe.Sizeof(src_err_list[0]))
func int2CInt(srcErrList []int) *C.int32_t {
var sizeErrInt = int(unsafe.Sizeof(srcErrList[0]))
switch sizeInt {
case sizeErrInt:
return (*C.int32_t)(unsafe.Pointer(&src_err_list[0]))
return (*C.int32_t)(unsafe.Pointer(&srcErrList[0]))
case sizeInt8:
int8Array := make([]int8, len(src_err_list))
for i, v := range src_err_list {
int8Array := make([]int8, len(srcErrList))
for i, v := range srcErrList {
int8Array[i] = int8(v)
}
return (*C.int32_t)(unsafe.Pointer(&int8Array[0]))
case sizeInt16:
int16Array := make([]int16, len(src_err_list))
for i, v := range src_err_list {
int16Array := make([]int16, len(srcErrList))
for i, v := range srcErrList {
int16Array[i] = int16(v)
}
return (*C.int32_t)(unsafe.Pointer(&int16Array[0]))
case sizeInt32:
int32Array := make([]int32, len(src_err_list))
for i, v := range src_err_list {
int32Array := make([]int32, len(srcErrList))
for i, v := range srcErrList {
int32Array[i] = int32(v)
}
return (*C.int32_t)(unsafe.Pointer(&int32Array[0]))
case sizeInt64:
int64Array := make([]int64, len(src_err_list))
for i, v := range src_err_list {
int64Array := make([]int64, len(srcErrList))
for i, v := range srcErrList {
int64Array[i] = int64(v)
}
return (*C.int32_t)(unsafe.Pointer(&int64Array[0]))

View File

@ -41,12 +41,13 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
m := int(e.params.M)
n := k + m
if len(chunks) != n {
return nil, errors.New(fmt.Sprintf("chunks length must be %d", n))
msg := fmt.Sprintf("chunks length must be %d", n)
return nil, errors.New(msg)
}
chunkLen := GetEncodedBlockLen(length, uint8(k))
errorIndex := make([]int, n+1)
var errCount int = 0
var errCount int
for i := range chunks {
// Check of chunks are really null
@ -63,7 +64,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
return nil, errors.New("too many erasures requested, can't decode")
}
errorIndex_ptr := int2CInt(errorIndex[:errCount])
errorIndexPtr := int2CInt(errorIndex[:errCount])
for i := range chunks {
if chunks[i] == nil || len(chunks[i]) == 0 {
@ -71,7 +72,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
}
}
C.minio_init_decoder(errorIndex_ptr, C.int(k), C.int(n), C.int(errCount-1),
C.minio_init_decoder(errorIndexPtr, C.int(k), C.int(n), C.int(errCount-1),
e.encodeMatrix, &decodeMatrix, &decodeTbls, &decodeIndex)
pointers := make([]*byte, n)
@ -81,7 +82,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
data := (**C.uint8_t)(unsafe.Pointer(&pointers[0]))
ret := C.minio_get_source_target(C.int(errCount-1), C.int(k), C.int(m), errorIndex_ptr,
ret := C.minio_get_source_target(C.int(errCount-1), C.int(k), C.int(m), errorIndexPtr,
decodeIndex, data, &source, &target)
if int(ret) == -1 {

View File

@ -26,19 +26,23 @@ import (
"unsafe"
)
// Technique - type of matrix type used in encoding
type Technique uint8
// Different types of supported matrix types
const (
Vandermonde Technique = iota
Cauchy
None
)
// Default Data and Parity blocks
const (
K = 10
M = 3
)
// Block alignment
const (
SIMDAlign = 32
)

View File

@ -21,17 +21,17 @@ package cpu
// int has_avx2 (void);
import "C"
// CPUID instruction verification wrapper for SSE41 extensions
// HasSSE41 - CPUID instruction verification wrapper for SSE41 extensions
func HasSSE41() bool {
return int(C.has_sse41()) == 1
}
// CPUID instruction verification wrapper for AVX extensions
// HasAVX - CPUID instruction verification wrapper for AVX extensions
func HasAVX() bool {
return int(C.has_avx()) == 1
}
// CPUID instruction verification wrapper for AVX2 extensions
// HasAVX2 - CPUID instruction verification wrapper for AVX2 extensions
func HasAVX2() bool {
return int(C.has_avx2()) == 1
}

View File

@ -98,10 +98,10 @@ func (d *digest) Write(p []byte) (nn int, err error) {
}
// Return checksum bytes
func (d0 *digest) Sum(in []byte) []byte {
func (d *digest) Sum(in []byte) []byte {
// Make a copy of d0 so that caller can keep writing and summing.
d := *d0
hash := d.checkSum()
d0 := *d
hash := d0.checkSum()
return append(in, hash[:]...)
}

View File

@ -6,6 +6,7 @@ import (
"crypto/sha512"
)
// The size of a SHA512 checksum in bytes.
const (
Size = sha512.Size
)