Permalink
Browse files

Stop exporting so many internals. Remove some dead code

  • Loading branch information...
1 parent 3400328 commit 05d080bbf32ea7a2f510dcfeaefef4afc6240d9a @brendonh committed Feb 9, 2013
Showing with 215 additions and 240 deletions.
  1. +63 −66 src/loge/database.go
  2. +54 −55 src/loge/leveldb.go
  3. +8 −8 src/loge/links.go
  4. +4 −4 src/loge/lock.go
  5. +9 −17 src/loge/objects.go
  6. +29 −31 src/loge/storage.go
  7. +44 −48 src/loge/transactions.go
  8. +0 −7 src/loge/typedefs.go
  9. +4 −4 src/loge/types.go
View
@@ -2,19 +2,14 @@ package loge
import (
"fmt"
- "crypto/rand"
"time"
)
-type typeMap map[string]*LogeType
-
-type objCache map[string]*LogeObject
-
type LogeDB struct {
types typeMap
store LogeStore
cache objCache
- lock SpinLock
+ lock spinLock
}
func NewLogeDB(store LogeStore) *LogeDB {
@@ -25,28 +20,36 @@ func NewLogeDB(store LogeStore) *LogeDB {
}
}
-type ObjRef struct {
+
+type typeMap map[string]*logeType
+
+type objCache map[string]*LogeObject
+
+type objRef struct {
TypeName string
Key LogeKey
LinkName string
CacheKey string
}
-func MakeObjRef(typeName string, key LogeKey) ObjRef {
+type Transactor func(*Transaction)
+
+
+func makeObjRef(typeName string, key LogeKey) objRef {
var cacheKey = typeName + "^" + string(key)
- return ObjRef { typeName, key, "", cacheKey }
+ return objRef { typeName, key, "", cacheKey }
}
-func MakeLinkRef(typeName string, linkName string, key LogeKey) ObjRef {
+func makeLinkRef(typeName string, linkName string, key LogeKey) objRef {
var cacheKey = "^" + typeName + "^" + linkName + "^" + string(key)
- return ObjRef { typeName, key, linkName, cacheKey }
+ return objRef { typeName, key, linkName, cacheKey }
}
-func (objRef ObjRef) String() string {
+func (objRef objRef) String() string {
return objRef.CacheKey
}
-func (objRef ObjRef) IsLink() bool {
+func (objRef objRef) IsLink() bool {
return objRef.LinkName != ""
}
@@ -55,31 +58,31 @@ func (db *LogeDB) Close() {
db.store.Close()
}
-func (db *LogeDB) CreateType(name string, version uint16, exemplar interface{}, linkSpec LinkSpec) *LogeType {
+func (db *LogeDB) CreateType(name string, version uint16, exemplar interface{}, linkSpec LinkSpec) *logeType {
_, ok := db.types[name]
if ok {
panic(fmt.Sprintf("Type exists: '%s'", name))
}
- var linkInfo = make(map[string]*LinkInfo)
+ var infos = make(map[string]*linkInfo)
for k, v := range linkSpec {
- linkInfo[k] = &LinkInfo {
+ infos[k] = &linkInfo{
Name: k,
Target: v,
Tag: 0,
}
}
- var t = &LogeType {
+ var t = &logeType {
Name: name,
Version: version,
Exemplar: exemplar,
- Links: linkInfo,
+ Links: infos,
}
db.types[name] = t
- db.store.RegisterType(t)
+ db.store.registerType(t)
return t
}
@@ -89,8 +92,6 @@ func (db *LogeDB) CreateTransaction() *Transaction {
return NewTransaction(db)
}
-type Transactor func(*Transaction)
-
func (db *LogeDB) Transact(actor Transactor, timeout time.Duration) bool {
var start = time.Now()
for {
@@ -106,11 +107,38 @@ func (db *LogeDB) Transact(actor Transactor, timeout time.Duration) bool {
return false
}
-func (db *LogeDB) EnsureObj(objRef ObjRef, load bool) *LogeObject {
- var typeName = objRef.TypeName
- var key = objRef.Key
+func (db *LogeDB) Find(typeName string, linkName string, target LogeKey) ResultSet {
+ typ, ok := db.types[typeName]
+ if !ok {
+ panic(fmt.Sprintf("Type does not exist: %s", typeName))
+ }
+ return db.store.Find(typ, linkName, target)
+}
+
- var objKey = objRef.String()
+func (db *LogeDB) FlushCache() int {
+ var count = 0
+ db.lock.SpinLock()
+ defer db.lock.Unlock()
+ for key, obj := range db.cache {
+ if obj.RefCount == 0 {
+ delete(db.cache, key)
+ count++
+ }
+ }
+ return count
+}
+
+
+// -----------------------------------------------
+// Internals
+// -----------------------------------------------
+
+func (db *LogeDB) ensureObj(ref objRef, load bool) *LogeObject {
+ var typeName = ref.TypeName
+ var key = ref.Key
+
+ var objKey = ref.String()
var typ = db.types[typeName]
db.lock.SpinLock()
@@ -122,7 +150,7 @@ func (db *LogeDB) EnsureObj(objRef ObjRef, load bool) *LogeObject {
}
if !ok {
- obj = InitializeObject(db, typ, key)
+ obj = initializeObject(db, typ, key)
}
obj.Lock.SpinLock()
@@ -132,22 +160,22 @@ func (db *LogeDB) EnsureObj(objRef ObjRef, load bool) *LogeObject {
db.lock.Unlock()
- var version *LogeObjectVersion
- if objRef.IsLink() {
- var links Links
+ var version *objectVersion
+ if ref.IsLink() {
+ var links []string
if load {
- links = db.store.GetLinks(typ, objRef.LinkName, key)
+ links = db.store.GetLinks(typ, ref.LinkName, key)
obj.Loaded = true
}
var linkSet = NewLinkSet()
linkSet.Original = links
- version = &LogeObjectVersion {
+ version = &objectVersion {
LogeObj: obj,
Version: 0,
Object: linkSet,
}
- obj.LinkName = objRef.LinkName
+ obj.LinkName = ref.LinkName
} else {
var object interface{}
@@ -161,7 +189,7 @@ func (db *LogeDB) EnsureObj(objRef ObjRef, load bool) *LogeObject {
object = typ.NilValue()
}
- version = &LogeObjectVersion{
+ version = &objectVersion{
Version: 0,
Object: object,
}
@@ -174,38 +202,7 @@ func (db *LogeDB) EnsureObj(objRef ObjRef, load bool) *LogeObject {
}
-func (db *LogeDB) Find(typeName string, linkName string, target LogeKey) ResultSet {
- typ, ok := db.types[typeName]
- if !ok {
- panic(fmt.Sprintf("Type does not exist: %s", typeName))
- }
- return db.store.Find(typ, linkName, target)
-}
-
-
-func (db *LogeDB) NewWriteBatch() LogeWriteBatch {
- return db.store.NewWriteBatch()
-}
-
-
-func (db *LogeDB) FlushCache() int {
- var count = 0
- db.lock.SpinLock()
- defer db.lock.Unlock()
- for key, obj := range db.cache {
- if obj.RefCount == 0 {
- delete(db.cache, key)
- count++
- }
- }
- return count
+func (db *LogeDB) newWriteBatch() writeBatch {
+ return db.store.newWriteBatch()
}
-func RandomLogeKey() string {
- var buf = make([]byte, 16)
- _, err := rand.Read(buf)
- if err != nil {
- panic("Couldn't generate key")
- }
- return fmt.Sprintf("%x", buf)
-}
Oops, something went wrong. Retry.

0 comments on commit 05d080b

Please sign in to comment.