mirror of
https://github.com/minio/minio.git
synced 2025-03-30 17:23:42 -04:00
Merge pull request #375 from harshavardhana/pr_out_golint_fixes
This commit is contained in:
commit
fab6892bc3
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/minio-io/iodine",
|
"ImportPath": "github.com/minio-io/iodine",
|
||||||
"Rev": "b279ca8ea714fabc969883a4d1612a4e93d01611"
|
"Rev": "f92ca01c8671d9565c7aa58e3427364c5e187ccf"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "gopkg.in/check.v1",
|
"ImportPath": "gopkg.in/check.v1",
|
||||||
|
60
Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go
generated
vendored
60
Godeps/_workspace/src/github.com/minio-io/iodine/iodine.go
generated
vendored
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Iodine, (C) 2014 Minio, Inc.
|
* Iodine, (C) 2015 Minio, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -21,8 +21,10 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,25 +45,30 @@ type StackEntry struct {
|
|||||||
Data map[string]string
|
Data map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var gopath string
|
||||||
|
|
||||||
var globalState = struct {
|
var globalState = struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
m map[string]string
|
m map[string]string
|
||||||
}{m: make(map[string]string)}
|
}{m: make(map[string]string)}
|
||||||
|
|
||||||
|
// SetGlobalState - set global state
|
||||||
func SetGlobalState(key, value string) {
|
func SetGlobalState(key, value string) {
|
||||||
globalState.Lock()
|
globalState.Lock()
|
||||||
globalState.m[key] = value
|
globalState.m[key] = value
|
||||||
globalState.Unlock()
|
globalState.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearGlobalState - clear info in globalState struct
|
||||||
func ClearGlobalState() {
|
func ClearGlobalState() {
|
||||||
globalState.Lock()
|
globalState.Lock()
|
||||||
for k, _ := range globalState.m {
|
for k := range globalState.m {
|
||||||
delete(globalState.m, k)
|
delete(globalState.m, k)
|
||||||
}
|
}
|
||||||
globalState.Unlock()
|
globalState.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGlobalState - get map from globalState struct
|
||||||
func GetGlobalState() map[string]string {
|
func GetGlobalState() map[string]string {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
globalState.RLock()
|
globalState.RLock()
|
||||||
@ -72,7 +79,16 @@ func GetGlobalState() map[string]string {
|
|||||||
return result
|
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.
|
// Adds an initial stack trace.
|
||||||
func New(err error, data map[string]string) *Error {
|
func New(err error, data map[string]string) *Error {
|
||||||
entry := createStackEntry()
|
entry := createStackEntry()
|
||||||
@ -86,18 +102,46 @@ func New(err error, data map[string]string) *Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createStackEntry - create stack entries
|
||||||
func createStackEntry() StackEntry {
|
func createStackEntry() StackEntry {
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
_, file, line, _ := runtime.Caller(2)
|
_, 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{
|
entry := StackEntry{
|
||||||
Host: host,
|
Host: host,
|
||||||
File: file,
|
File: file,
|
||||||
Line: line,
|
Line: line,
|
||||||
Data: GetGlobalState(),
|
Data: data,
|
||||||
}
|
}
|
||||||
return entry
|
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
|
// Annotate an error with a stack entry and returns itself
|
||||||
func (err *Error) Annotate(info map[string]string) *Error {
|
func (err *Error) Annotate(info map[string]string) *Error {
|
||||||
entry := createStackEntry()
|
entry := createStackEntry()
|
||||||
@ -127,3 +171,11 @@ func (err Error) EmitHumanReadable() string {
|
|||||||
func (err Error) Error() string {
|
func (err Error) Error() string {
|
||||||
return err.EmbeddedError.Error()
|
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
|
||||||
|
}
|
||||||
|
16
Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go
generated
vendored
16
Godeps/_workspace/src/github.com/minio-io/iodine/iodine_test.go
generated
vendored
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Iodine, (C) 2014 Minio, Inc.
|
* Iodine, (C) 2015 Minio, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -20,7 +20,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,16 +37,16 @@ func TestIodine(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var prettyBuffer bytes.Buffer
|
var prettyBuffer bytes.Buffer
|
||||||
json.Indent(&prettyBuffer, jsonResult, "", " ")
|
json.Indent(&prettyBuffer, jsonResult, "", " ")
|
||||||
|
if prettyBuffer.String() == "" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestState(t *testing.T) {
|
func TestState(t *testing.T) {
|
||||||
SetGlobalState("hello", "world")
|
SetGlobalState("hello", "world")
|
||||||
state := GetGlobalState()
|
result := GetGlobalStateKey("hello")
|
||||||
if res, ok := state["hello"]; ok {
|
if result != "world" {
|
||||||
if res != "world" {
|
t.Error("global state not set: hello->world")
|
||||||
t.Error("global state not set: hello->world")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
ClearGlobalState()
|
ClearGlobalState()
|
||||||
@ -85,7 +84,6 @@ func TestState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err.Annotate(nil)
|
err.Annotate(nil)
|
||||||
log.Println(err.EmitHumanReadable())
|
|
||||||
t.Error("foo2 should be set")
|
t.Error("foo2 should be set")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,32 +24,32 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Integer to Int conversion
|
// Integer to Int conversion
|
||||||
func int2CInt(src_err_list []int) *C.int32_t {
|
func int2CInt(srcErrList []int) *C.int32_t {
|
||||||
var sizeErrInt = int(unsafe.Sizeof(src_err_list[0]))
|
var sizeErrInt = int(unsafe.Sizeof(srcErrList[0]))
|
||||||
switch sizeInt {
|
switch sizeInt {
|
||||||
case sizeErrInt:
|
case sizeErrInt:
|
||||||
return (*C.int32_t)(unsafe.Pointer(&src_err_list[0]))
|
return (*C.int32_t)(unsafe.Pointer(&srcErrList[0]))
|
||||||
case sizeInt8:
|
case sizeInt8:
|
||||||
int8Array := make([]int8, len(src_err_list))
|
int8Array := make([]int8, len(srcErrList))
|
||||||
for i, v := range src_err_list {
|
for i, v := range srcErrList {
|
||||||
int8Array[i] = int8(v)
|
int8Array[i] = int8(v)
|
||||||
}
|
}
|
||||||
return (*C.int32_t)(unsafe.Pointer(&int8Array[0]))
|
return (*C.int32_t)(unsafe.Pointer(&int8Array[0]))
|
||||||
case sizeInt16:
|
case sizeInt16:
|
||||||
int16Array := make([]int16, len(src_err_list))
|
int16Array := make([]int16, len(srcErrList))
|
||||||
for i, v := range src_err_list {
|
for i, v := range srcErrList {
|
||||||
int16Array[i] = int16(v)
|
int16Array[i] = int16(v)
|
||||||
}
|
}
|
||||||
return (*C.int32_t)(unsafe.Pointer(&int16Array[0]))
|
return (*C.int32_t)(unsafe.Pointer(&int16Array[0]))
|
||||||
case sizeInt32:
|
case sizeInt32:
|
||||||
int32Array := make([]int32, len(src_err_list))
|
int32Array := make([]int32, len(srcErrList))
|
||||||
for i, v := range src_err_list {
|
for i, v := range srcErrList {
|
||||||
int32Array[i] = int32(v)
|
int32Array[i] = int32(v)
|
||||||
}
|
}
|
||||||
return (*C.int32_t)(unsafe.Pointer(&int32Array[0]))
|
return (*C.int32_t)(unsafe.Pointer(&int32Array[0]))
|
||||||
case sizeInt64:
|
case sizeInt64:
|
||||||
int64Array := make([]int64, len(src_err_list))
|
int64Array := make([]int64, len(srcErrList))
|
||||||
for i, v := range src_err_list {
|
for i, v := range srcErrList {
|
||||||
int64Array[i] = int64(v)
|
int64Array[i] = int64(v)
|
||||||
}
|
}
|
||||||
return (*C.int32_t)(unsafe.Pointer(&int64Array[0]))
|
return (*C.int32_t)(unsafe.Pointer(&int64Array[0]))
|
||||||
|
@ -41,12 +41,13 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
|
|||||||
m := int(e.params.M)
|
m := int(e.params.M)
|
||||||
n := k + m
|
n := k + m
|
||||||
if len(chunks) != n {
|
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))
|
chunkLen := GetEncodedBlockLen(length, uint8(k))
|
||||||
|
|
||||||
errorIndex := make([]int, n+1)
|
errorIndex := make([]int, n+1)
|
||||||
var errCount int = 0
|
var errCount int
|
||||||
|
|
||||||
for i := range chunks {
|
for i := range chunks {
|
||||||
// Check of chunks are really null
|
// 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")
|
return nil, errors.New("too many erasures requested, can't decode")
|
||||||
}
|
}
|
||||||
|
|
||||||
errorIndex_ptr := int2CInt(errorIndex[:errCount])
|
errorIndexPtr := int2CInt(errorIndex[:errCount])
|
||||||
|
|
||||||
for i := range chunks {
|
for i := range chunks {
|
||||||
if chunks[i] == nil || len(chunks[i]) == 0 {
|
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)
|
e.encodeMatrix, &decodeMatrix, &decodeTbls, &decodeIndex)
|
||||||
|
|
||||||
pointers := make([]*byte, n)
|
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]))
|
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)
|
decodeIndex, data, &source, &target)
|
||||||
|
|
||||||
if int(ret) == -1 {
|
if int(ret) == -1 {
|
||||||
|
@ -26,19 +26,23 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Technique - type of matrix type used in encoding
|
||||||
type Technique uint8
|
type Technique uint8
|
||||||
|
|
||||||
|
// Different types of supported matrix types
|
||||||
const (
|
const (
|
||||||
Vandermonde Technique = iota
|
Vandermonde Technique = iota
|
||||||
Cauchy
|
Cauchy
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Default Data and Parity blocks
|
||||||
const (
|
const (
|
||||||
K = 10
|
K = 10
|
||||||
M = 3
|
M = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Block alignment
|
||||||
const (
|
const (
|
||||||
SIMDAlign = 32
|
SIMDAlign = 32
|
||||||
)
|
)
|
||||||
|
@ -21,17 +21,17 @@ package cpu
|
|||||||
// int has_avx2 (void);
|
// int has_avx2 (void);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// CPUID instruction verification wrapper for SSE41 extensions
|
// HasSSE41 - CPUID instruction verification wrapper for SSE41 extensions
|
||||||
func HasSSE41() bool {
|
func HasSSE41() bool {
|
||||||
return int(C.has_sse41()) == 1
|
return int(C.has_sse41()) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPUID instruction verification wrapper for AVX extensions
|
// HasAVX - CPUID instruction verification wrapper for AVX extensions
|
||||||
func HasAVX() bool {
|
func HasAVX() bool {
|
||||||
return int(C.has_avx()) == 1
|
return int(C.has_avx()) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPUID instruction verification wrapper for AVX2 extensions
|
// HasAVX2 - CPUID instruction verification wrapper for AVX2 extensions
|
||||||
func HasAVX2() bool {
|
func HasAVX2() bool {
|
||||||
return int(C.has_avx2()) == 1
|
return int(C.has_avx2()) == 1
|
||||||
}
|
}
|
||||||
|
@ -98,10 +98,10 @@ func (d *digest) Write(p []byte) (nn int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return checksum bytes
|
// 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.
|
// Make a copy of d0 so that caller can keep writing and summing.
|
||||||
d := *d0
|
d0 := *d
|
||||||
hash := d.checkSum()
|
hash := d0.checkSum()
|
||||||
return append(in, hash[:]...)
|
return append(in, hash[:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The size of a SHA512 checksum in bytes.
|
||||||
const (
|
const (
|
||||||
Size = sha512.Size
|
Size = sha512.Size
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user