2011-11-02 01:37:27 +00:00
/ *
Copyright 2011 Google Inc .
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
package index
import (
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
"errors"
2012-10-08 14:16:00 +00:00
"fmt"
2013-08-27 02:07:28 +00:00
"io"
2011-11-28 03:29:23 +00:00
"log"
2011-11-02 01:37:27 +00:00
"os"
2011-11-29 19:40:15 +00:00
"strconv"
2011-11-28 03:29:23 +00:00
"strings"
2013-02-19 05:31:41 +00:00
"sync"
2011-11-02 01:37:27 +00:00
"time"
2013-08-04 02:54:30 +00:00
"camlistore.org/pkg/blob"
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
"camlistore.org/pkg/blobserver"
"camlistore.org/pkg/search"
2013-02-19 05:31:41 +00:00
"camlistore.org/pkg/types"
2011-11-02 01:37:27 +00:00
)
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
var ErrNotFound = errors . New ( "index: key not found" )
2011-11-11 02:58:04 +00:00
2013-07-07 23:09:17 +00:00
// Storage is the minimal interface that must be implemented by index
// storage implementations. (e.g. mysql, postgres, mongo, sqlite,
// leveldb, dynamo)
2013-01-14 04:19:36 +00:00
type Storage interface {
2011-11-11 02:58:04 +00:00
// Get gets the value for the given key. It returns ErrNotFound if the DB
// does not contain the key.
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
Get ( key string ) ( string , error )
2011-11-11 02:58:04 +00:00
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
Set ( key , value string ) error
Delete ( key string ) error
2011-11-09 16:21:19 +00:00
BeginBatch ( ) BatchMutation
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
CommitBatch ( b BatchMutation ) error
2011-11-10 18:28:44 +00:00
// Find returns an iterator positioned before the first key/value pair
// whose key is 'greater than or equal to' the given key. There may be no
// such pair, in which case the iterator will return false on Next.
//
// Any error encountered will be implicitly returned via the iterator. An
// error-iterator will yield no key/value pairs and closing that iterator
// will return that error.
Find ( key string ) Iterator
}
// Iterator iterates over an index Storage's key/value pairs in key order.
//
// An iterator must be closed after use, but it is not necessary to read an
// iterator until exhaustion.
//
// An iterator is not necessarily goroutine-safe, but it is safe to use
// multiple iterators concurrently, with each in a dedicated goroutine.
type Iterator interface {
// Next moves the iterator to the next key/value pair.
2013-01-09 22:21:32 +00:00
// It returns false when the iterator is exhausted.
2011-11-10 18:28:44 +00:00
Next ( ) bool
// Key returns the key of the current key/value pair.
// Only valid after a call to Next returns true.
Key ( ) string
// Value returns the value of the current key/value pair.
// Only valid after a call to Next returns true.
Value ( ) string
// Close closes the iterator and returns any accumulated error. Exhausting
// all the key/value pairs in a table is not considered to be an error.
// It is valid to call Close multiple times. Other methods should not be
// called after the iterator has been closed.
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
Close ( ) error
2011-11-09 16:21:19 +00:00
}
type BatchMutation interface {
Set ( key , value string )
Delete ( key string )
}
2012-02-26 12:49:03 +00:00
type Mutation interface {
Key ( ) string
Value ( ) string
IsDelete ( ) bool
}
2011-11-09 16:21:19 +00:00
type mutation struct {
key string
value string // used if !delete
delete bool // if to be deleted
}
2012-02-26 12:49:03 +00:00
func ( m mutation ) Key ( ) string {
return m . key
}
func ( m mutation ) Value ( ) string {
return m . value
}
func ( m mutation ) IsDelete ( ) bool {
return m . delete
}
func NewBatchMutation ( ) BatchMutation {
return & batch { }
}
2011-11-09 16:21:19 +00:00
type batch struct {
2012-02-26 12:49:03 +00:00
m [ ] Mutation
}
func ( b * batch ) Mutations ( ) [ ] Mutation {
return b . m
2011-11-09 16:21:19 +00:00
}
func ( b * batch ) Delete ( key string ) {
b . m = append ( b . m , mutation { key : key , delete : true } )
}
func ( b * batch ) Set ( key , value string ) {
b . m = append ( b . m , mutation { key : key , value : value } )
2011-11-02 01:37:27 +00:00
}
type Index struct {
2011-11-07 16:40:31 +00:00
* blobserver . NoImplStorage
2013-01-14 04:19:36 +00:00
s Storage
2011-11-07 16:40:31 +00:00
2013-08-04 02:54:30 +00:00
KeyFetcher blob . StreamingFetcher // for verifying claims
2011-11-07 16:40:31 +00:00
// Used for fetching blobs to find the complete sha1s of file & bytes
// schema blobs.
2013-08-04 02:54:30 +00:00
BlobSource blob . StreamingFetcher
2013-11-04 22:15:24 +00:00
// deletes is a cache to keep track of the deletion status (deleted vs undeleted)
// of the blobs in the index. It makes for faster reads than the otherwise
// recursive calls on the index.
deletes * deletionCache
2011-11-02 01:37:27 +00:00
}
var _ blobserver . Storage = ( * Index ) ( nil )
var _ search . Index = ( * Index ) ( nil )
2013-01-14 04:19:36 +00:00
func New ( s Storage ) * Index {
2013-11-04 22:15:24 +00:00
idx := & Index { s : s }
schemaVersion := idx . schemaVersion ( )
if schemaVersion != 0 {
if schemaVersion != requiredSchemaVersion {
if os . Getenv ( "CAMLI_DEV_CAMLI_ROOT" ) != "" {
// Good signal that we're using the devcam server, so help out
// the user with a more useful tip:
log . Fatalf ( "index schema version is %d; required one is %d (run \"devcam server --wipe\" to wipe both your blobs and reindex.)" , schemaVersion , requiredSchemaVersion )
}
log . Fatalf ( "index schema version is %d; required one is %d. You need to reindex. See 'camtool dbinit' (or just delete the file for a file based index), and then 'camtool sync'.)" ,
schemaVersion , requiredSchemaVersion )
}
} else {
err := idx . s . Set ( keySchemaVersion . name , fmt . Sprintf ( "%d" , requiredSchemaVersion ) )
if err != nil {
panic ( fmt . Errorf ( "Could not write index schema version %q: %v" , requiredSchemaVersion , err ) )
}
}
if err := idx . initDeletesCache ( ) ; err != nil {
panic ( fmt . Errorf ( "Could not initialize index's deletes cache: %v" , err ) )
}
return idx
2011-11-02 01:37:27 +00:00
}
2011-11-29 22:33:10 +00:00
type prefixIter struct {
Iterator
prefix string
}
func ( p * prefixIter ) Next ( ) bool {
v := p . Iterator . Next ( )
if v && ! strings . HasPrefix ( p . Key ( ) , p . prefix ) {
return false
}
return v
}
func ( x * Index ) queryPrefix ( key * keyType , args ... interface { } ) * prefixIter {
return x . queryPrefixString ( key . Prefix ( args ... ) )
}
func ( x * Index ) queryPrefixString ( prefix string ) * prefixIter {
return & prefixIter {
prefix : prefix ,
Iterator : x . s . Find ( prefix ) ,
}
}
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
func closeIterator ( it Iterator , perr * error ) {
2011-12-03 19:26:42 +00:00
err := it . Close ( )
if err != nil && * perr == nil {
* perr = err
}
}
2013-11-04 22:15:24 +00:00
// schemaVersion returns the version of schema as it is found
// in the currently used index. If not found, it returns 0.
func ( x * Index ) schemaVersion ( ) int {
schemaVersionStr , err := x . s . Get ( keySchemaVersion . name )
if err != nil {
if err == ErrNotFound {
return 0
}
panic ( fmt . Errorf ( "Could not get index schema version: %v" , err ) )
}
schemaVersion , err := strconv . Atoi ( schemaVersionStr )
if err != nil {
panic ( fmt . Errorf ( "Bogus index schema version: %q" , schemaVersionStr ) )
}
return schemaVersion
}
type deletionStatus struct {
deleted bool // whether the concerned blob should be considered deleted.
when time . Time // time of the most recent (un)deletion
}
type deletionCache struct {
sync . RWMutex
m map [ blob . Ref ] deletionStatus
}
// initDeletesCache creates and populates the deletion status cache used by the index
// for faster calls to IsDeleted and DeletedAt. It is called by New.
func ( x * Index ) initDeletesCache ( ) error {
x . deletes = & deletionCache {
m : make ( map [ blob . Ref ] deletionStatus ) ,
}
2012-10-08 14:16:00 +00:00
var err error
2013-11-04 22:15:24 +00:00
it := x . queryPrefix ( keyDeleted )
2012-10-08 14:16:00 +00:00
defer closeIterator ( it , & err )
for it . Next ( ) {
2013-11-04 22:15:24 +00:00
parts := strings . SplitN ( it . Key ( ) , "|" , 4 )
if len ( parts ) != 4 {
return fmt . Errorf ( "Bogus keyDeleted entry key: want |\"deleted\"|<deleted blobref>|<reverse claimdate>|<deleter claim>|, got %q" , it . Key ( ) )
}
deleter := parts [ 3 ]
deleterRef , ok := blob . Parse ( deleter )
if ! ok {
return fmt . Errorf ( "invalid deleter blobref %q in keyDeleted entry %q" , deleter , it . Key ( ) )
}
deleted := parts [ 1 ]
deletedRef , ok := blob . Parse ( deleted )
if ! ok {
return fmt . Errorf ( "invalid deleted blobref %q in keyDeleted entry %q" , deleted , it . Key ( ) )
}
delTimeStr := parts [ 2 ]
delTime , err := time . Parse ( time . RFC3339 , unreverseTimeString ( delTimeStr ) )
if err != nil {
return fmt . Errorf ( "invalid time %q in keyDeleted entry %q: %v" , delTimeStr , it . Key ( ) , err )
}
deleterIsDeleted , when := x . deletedAtNoCache ( deleterRef )
if when . IsZero ( ) {
when = delTime
}
previousStatus , ok := x . deletes . m [ deletedRef ]
if ok && when . Before ( previousStatus . when ) {
// previously noted status wins because it is the most recent
continue
}
x . deletes . m [ deletedRef ] = deletionStatus {
deleted : ! deleterIsDeleted ,
when : when ,
}
}
return err
}
// UpdateDeletesCache updates the index deletes cache with the deletion
// (and its potential consequences) of deletedRef at when.
func ( x * Index ) UpdateDeletesCache ( deletedRef blob . Ref , when time . Time ) error {
// TODO(mpl): This one will go away as soon as receive.go handles delete claims and is in charge
// of keeping the cache updated. Or at least it won't have to be public. Now I need it public
// for the tests.
var err error
if x . deletes == nil {
return fmt . Errorf ( "Index has no deletes cache" )
}
x . deletes . Lock ( )
defer x . deletes . Unlock ( )
previousStatus := x . deletes . m [ deletedRef ]
if when . Before ( previousStatus . when ) {
// ignore new value because it's older than what's in cache
return err
}
x . deletes . m [ deletedRef ] = deletionStatus {
deleted : true ,
when : when ,
}
// And now deal with the consequences
isDeleted := true
for {
isDeleted = ! isDeleted
deleterRef := deletedRef
it := x . queryPrefix ( keyDeletes , deleterRef )
defer closeIterator ( it , & err )
if ! it . Next ( ) {
break
}
2012-10-08 14:16:00 +00:00
parts := strings . SplitN ( it . Key ( ) , "|" , 3 )
if len ( parts ) != 3 {
2013-11-04 22:15:24 +00:00
return fmt . Errorf ( "Bogus keyDeletes entry key: want |\"deletes\"|<deleter claim>|<deleted blob>|, got %q" , it . Key ( ) )
}
deleted := parts [ 2 ]
var ok bool
deletedRef , ok = blob . Parse ( deleted )
if ! ok {
return fmt . Errorf ( "invalid deleted blobref %q in keyDeletes entry %q" , deleted , it . Key ( ) )
}
x . deletes . m [ deletedRef ] = deletionStatus {
deleted : isDeleted ,
when : when ,
}
}
return err
}
// DeletedAt returns whether br (a blobref or a claim) should be considered deleted,
// and at what time the latest deletion or undeletion occured. If it was never deleted,
// it returns false, time.Time{}.
func ( x * Index ) DeletedAt ( br blob . Ref ) ( bool , time . Time ) {
if x . deletes == nil {
// We still allow the slow path, in case someone creates
// their own Index without a deletes cache.
return x . deletedAtNoCache ( br )
}
x . deletes . RLock ( )
defer x . deletes . RUnlock ( )
st := x . deletes . m [ br ]
return st . deleted , st . when
}
func ( x * Index ) deletedAtNoCache ( br blob . Ref ) ( bool , time . Time ) {
var err error
it := x . queryPrefix ( keyDeleted , br )
if it . Next ( ) {
parts := strings . SplitN ( it . Key ( ) , "|" , 4 )
if len ( parts ) != 4 {
panic ( fmt . Errorf ( "Bogus keyDeleted entry key: want |\"deleted\"|<deleted blobref>|<reverse claimdate>|<deleter claim>|, got %q" , it . Key ( ) ) )
}
deleter := parts [ 3 ]
deleterRef , ok := blob . Parse ( deleter )
if ! ok {
panic ( fmt . Errorf ( "invalid deleter blobref %q in keyDeleted entry %q" , deleter , it . Key ( ) ) )
}
delTime := parts [ 2 ]
mTime , err := time . Parse ( time . RFC3339 , unreverseTimeString ( delTime ) )
if err != nil {
panic ( fmt . Errorf ( "invalid time %q in keyDeleted entry %q: %v" , delTime , it . Key ( ) , err ) )
2012-10-08 14:16:00 +00:00
}
2013-11-04 22:15:24 +00:00
closeIterator ( it , & err )
if err != nil {
// TODO: Do better?
panic ( fmt . Errorf ( "Could not close iterator on keyDeleted: %v" , err ) )
}
del , when := x . deletedAtNoCache ( deleterRef )
if when . IsZero ( ) {
when = mTime
}
return ! del , when
}
closeIterator ( it , & err )
if err != nil {
// TODO: Do better?
panic ( fmt . Errorf ( "Could not close iterator on keyDeleted: %v" , err ) )
}
return false , time . Time { }
}
2013-11-10 00:20:21 +00:00
// IsDeleted reports whether the provided blobref (of a permanode or
// claim) should be considered deleted.
2013-11-04 22:15:24 +00:00
func ( x * Index ) IsDeleted ( br blob . Ref ) bool {
if x . deletes == nil {
// We still allow the slow path, in case someone creates
// their own Index without a deletes cache.
return x . isDeletedNoCache ( br )
}
x . deletes . RLock ( )
defer x . deletes . RUnlock ( )
st := x . deletes . m [ br ]
return st . deleted
}
func ( x * Index ) isDeletedNoCache ( br blob . Ref ) bool {
var err error
it := x . queryPrefix ( keyDeleted , br )
if it . Next ( ) {
parts := strings . SplitN ( it . Key ( ) , "|" , 4 )
if len ( parts ) != 4 {
panic ( fmt . Errorf ( "Bogus keyDeleted entry key: want |\"deleted\"|<deleted blobref>|<reverse claimdate>|<deleter claim>|, got %q" , it . Key ( ) ) )
}
deleter := parts [ 3 ]
delClaimRef , ok := blob . Parse ( deleter )
2013-08-04 02:54:30 +00:00
if ! ok {
2013-11-04 22:15:24 +00:00
panic ( fmt . Errorf ( "invalid deleter blobref %q in keyDeleted entry %q" , deleter , it . Key ( ) ) )
2012-10-08 14:16:00 +00:00
}
// The recursive call on the blobref of the delete claim
// checks that the claim itself was not deleted, in which case
// br is not considered deleted anymore.
// TODO(mpl): Each delete and undo delete adds a level of
// recursion so this could recurse far. is there a way to
// go faster in a worst case scenario?
2013-11-04 22:15:24 +00:00
closeIterator ( it , & err )
if err != nil {
// TODO: Do better?
panic ( fmt . Errorf ( "Could not close iterator on keyDeleted: %v" , err ) )
}
return ! x . isDeletedNoCache ( delClaimRef )
}
closeIterator ( it , & err )
if err != nil {
// TODO: Do better?
panic ( fmt . Errorf ( "Could not close iterator on keyDeleted: %v" , err ) )
2012-10-08 14:16:00 +00:00
}
return false
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) GetRecentPermanodes ( dest chan * search . Result , owner blob . Ref , limit int ) ( err error ) {
2011-11-02 01:37:27 +00:00
defer close ( dest )
2011-11-29 19:19:32 +00:00
keyId , err := x . keyId ( owner )
if err == ErrNotFound {
2013-01-09 22:21:32 +00:00
log . Printf ( "No recent permanodes because keyId for owner %v not found" , owner )
2011-11-29 19:19:32 +00:00
return nil
}
if err != nil {
2013-01-09 22:21:32 +00:00
log . Printf ( "Error fetching keyId for owner %v: %v" , owner , err )
2011-11-29 19:19:32 +00:00
return err
}
sent := 0
var seenPermanode dupSkipper
2011-11-29 22:33:10 +00:00
it := x . queryPrefix ( keyRecentPermanode , keyId )
2011-12-03 19:26:42 +00:00
defer closeIterator ( it , & err )
2011-11-29 19:19:32 +00:00
for it . Next ( ) {
permaStr := it . Value ( )
parts := strings . SplitN ( it . Key ( ) , "|" , 4 )
if len ( parts ) != 4 {
continue
}
2012-05-13 20:27:11 +00:00
var mTimeSec int64
if mTime , err := time . Parse ( time . RFC3339 , unreverseTimeString ( parts [ 2 ] ) ) ; err == nil {
mTimeSec = mTime . Unix ( )
}
2013-08-04 02:54:30 +00:00
permaRef , ok := blob . Parse ( permaStr )
if ! ok {
2011-11-29 19:19:32 +00:00
continue
}
2013-11-04 22:15:24 +00:00
if x . IsDeleted ( permaRef ) {
2012-10-08 14:16:00 +00:00
continue
}
2011-11-29 19:19:32 +00:00
if seenPermanode . Dup ( permaStr ) {
continue
}
dest <- & search . Result {
BlobRef : permaRef ,
Signer : owner , // TODO(bradfitz): kinda. usually. for now.
LastModTime : mTimeSec ,
}
sent ++
if sent == limit {
break
}
}
return nil
2011-11-02 01:37:27 +00:00
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) GetOwnerClaims ( permaNode , owner blob . Ref ) ( cl search . ClaimList , err error ) {
2011-11-29 20:40:33 +00:00
keyId , err := x . keyId ( owner )
if err == ErrNotFound {
err = nil
return
}
if err != nil {
return nil , err
}
2013-11-07 00:09:11 +00:00
it := x . queryPrefix ( keyPermanodeClaim , permaNode , keyId )
2011-12-03 19:26:42 +00:00
defer closeIterator ( it , & err )
2011-11-29 20:40:33 +00:00
for it . Next ( ) {
keyPart := strings . Split ( it . Key ( ) , "|" )
valPart := strings . Split ( it . Value ( ) , "|" )
if len ( keyPart ) < 5 || len ( valPart ) < 3 {
continue
}
2013-08-04 02:54:30 +00:00
claimRef , ok := blob . Parse ( keyPart [ 4 ] )
if ! ok {
2011-11-29 20:40:33 +00:00
continue
}
2012-05-13 20:27:11 +00:00
date , _ := time . Parse ( time . RFC3339 , keyPart [ 3 ] )
2011-11-29 20:40:33 +00:00
cl = append ( cl , & search . Claim {
BlobRef : claimRef ,
Signer : owner ,
Permanode : permaNode ,
2012-05-13 20:27:11 +00:00
Date : date ,
2011-11-29 20:40:33 +00:00
Type : urld ( valPart [ 0 ] ) ,
Attr : urld ( valPart [ 1 ] ) ,
Value : urld ( valPart [ 2 ] ) ,
} )
}
return
2011-11-02 01:37:27 +00:00
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) GetBlobMIMEType ( blob blob . Ref ) ( mime string , size int64 , err error ) {
2013-01-09 03:43:09 +00:00
key := "meta:" + blob . String ( )
meta , err := x . s . Get ( key )
2011-11-29 19:40:15 +00:00
if err == ErrNotFound {
2012-02-20 12:32:46 +00:00
err = os . ErrNotExist
2011-11-29 19:40:15 +00:00
}
if err != nil {
return
}
pos := strings . Index ( meta , "|" )
2013-01-09 03:43:09 +00:00
if pos < 0 {
panic ( fmt . Sprintf ( "Bogus index row for key %q: got value %q" , key , meta ) )
}
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
size , _ = strconv . ParseInt ( meta [ : pos ] , 10 , 64 )
2011-11-29 19:40:15 +00:00
mime = meta [ pos + 1 : ]
2011-11-02 01:37:27 +00:00
return
}
2011-11-28 03:29:23 +00:00
// maps from blobref of openpgp ascii-armored public key => gpg keyid like "2931A67C26F5ABDA"
2013-08-04 02:54:30 +00:00
func ( x * Index ) keyId ( signer blob . Ref ) ( string , error ) {
2011-11-28 03:29:23 +00:00
return x . s . Get ( "signerkeyid:" + signer . String ( ) )
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) PermanodeOfSignerAttrValue ( signer blob . Ref , attr , val string ) ( permaNode blob . Ref , err error ) {
2011-11-28 03:29:23 +00:00
keyId , err := x . keyId ( signer )
2011-11-29 19:19:32 +00:00
if err == ErrNotFound {
2013-08-04 02:54:30 +00:00
return blob . Ref { } , os . ErrNotExist
2011-11-28 03:29:23 +00:00
}
2011-11-29 19:19:32 +00:00
if err != nil {
2013-08-04 02:54:30 +00:00
return blob . Ref { } , err
2011-11-29 19:19:32 +00:00
}
2011-12-04 22:47:05 +00:00
it := x . queryPrefix ( keySignerAttrValue , keyId , attr , val )
2011-12-03 19:26:42 +00:00
defer closeIterator ( it , & err )
2011-11-28 03:29:23 +00:00
if it . Next ( ) {
2013-08-04 02:54:30 +00:00
permaRef , ok := blob . Parse ( it . Value ( ) )
2013-11-04 22:15:24 +00:00
if ok && ! x . IsDeleted ( permaRef ) {
2012-10-08 14:16:00 +00:00
return permaRef , nil
}
2011-11-28 03:29:23 +00:00
}
2013-08-04 02:54:30 +00:00
return blob . Ref { } , os . ErrNotExist
2011-11-02 01:37:27 +00:00
}
2011-12-04 22:47:05 +00:00
// This is just like PermanodeOfSignerAttrValue except we return multiple and dup-suppress.
2012-11-13 23:02:12 +00:00
// If request.Query is "", it is not used in the prefix search.
2013-08-04 02:54:30 +00:00
func ( x * Index ) SearchPermanodesWithAttr ( dest chan <- blob . Ref , request * search . PermanodeByAttrRequest ) ( err error ) {
2011-12-04 22:47:05 +00:00
defer close ( dest )
if request . FuzzyMatch {
// TODO(bradfitz): remove this for now? figure out how to handle it generically?
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
return errors . New ( "TODO: SearchPermanodesWithAttr: generic indexer doesn't support FuzzyMatch on PermanodeByAttrRequest" )
2011-12-04 22:47:05 +00:00
}
if request . Attribute == "" {
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
return errors . New ( "index: missing Attribute in SearchPermanodesWithAttr" )
2011-12-04 22:47:05 +00:00
}
keyId , err := x . keyId ( request . Signer )
if err == ErrNotFound {
return nil
}
if err != nil {
return err
}
seen := make ( map [ string ] bool )
2012-11-13 23:02:12 +00:00
var it * prefixIter
if request . Query == "" {
it = x . queryPrefix ( keySignerAttrValue , keyId , request . Attribute )
} else {
it = x . queryPrefix ( keySignerAttrValue , keyId , request . Attribute , request . Query )
}
2011-12-04 22:47:05 +00:00
defer closeIterator ( it , & err )
for it . Next ( ) {
2013-08-04 02:54:30 +00:00
pn , ok := blob . Parse ( it . Value ( ) )
if ! ok {
2011-12-04 22:47:05 +00:00
continue
}
2013-11-04 22:15:24 +00:00
if x . IsDeleted ( pn ) {
2012-10-08 14:16:00 +00:00
continue
}
2011-12-04 22:47:05 +00:00
pnstr := pn . String ( )
if seen [ pnstr ] {
continue
}
seen [ pnstr ] = true
dest <- pn
if len ( seen ) == request . MaxResults {
break
}
}
return nil
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) PathsOfSignerTarget ( signer , target blob . Ref ) ( paths [ ] * search . Path , err error ) {
2011-12-01 18:43:57 +00:00
paths = [ ] * search . Path { }
keyId , err := x . keyId ( signer )
if err != nil {
if err == ErrNotFound {
err = nil
}
return
}
mostRecent := make ( map [ string ] * search . Path )
maxClaimDates := make ( map [ string ] string )
2011-12-02 02:06:25 +00:00
it := x . queryPrefix ( keyPathBackward , keyId , target )
2011-12-03 19:26:42 +00:00
defer closeIterator ( it , & err )
2011-12-01 18:43:57 +00:00
for it . Next ( ) {
2011-12-02 01:28:32 +00:00
keyPart := strings . Split ( it . Key ( ) , "|" ) [ 1 : ]
2011-12-01 18:43:57 +00:00
valPart := strings . Split ( it . Value ( ) , "|" )
if len ( keyPart ) < 3 || len ( valPart ) < 4 {
continue
}
2013-08-04 02:54:30 +00:00
claimRef , ok := blob . Parse ( keyPart [ 2 ] )
if ! ok {
continue
}
baseRef , ok := blob . Parse ( valPart [ 1 ] )
if ! ok {
2011-12-01 18:43:57 +00:00
continue
}
claimDate := valPart [ 0 ]
active := valPart [ 2 ]
suffix := urld ( valPart [ 3 ] )
key := baseRef . String ( ) + "/" + suffix
if claimDate > maxClaimDates [ key ] {
maxClaimDates [ key ] = claimDate
if active == "Y" {
mostRecent [ key ] = & search . Path {
Claim : claimRef ,
ClaimDate : claimDate ,
Base : baseRef ,
Suffix : suffix ,
2011-12-02 01:28:32 +00:00
Target : target ,
2011-12-01 18:43:57 +00:00
}
} else {
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
delete ( mostRecent , key )
2011-12-01 18:43:57 +00:00
}
}
}
for _ , v := range mostRecent {
paths = append ( paths , v )
}
return paths , nil
2011-11-02 01:37:27 +00:00
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) PathsLookup ( signer , base blob . Ref , suffix string ) ( paths [ ] * search . Path , err error ) {
2011-12-02 02:06:25 +00:00
paths = [ ] * search . Path { }
keyId , err := x . keyId ( signer )
if err != nil {
if err == ErrNotFound {
err = nil
}
return
}
it := x . queryPrefix ( keyPathForward , keyId , base , suffix )
2011-12-03 19:26:42 +00:00
defer closeIterator ( it , & err )
2011-12-02 02:06:25 +00:00
for it . Next ( ) {
keyPart := strings . Split ( it . Key ( ) , "|" ) [ 1 : ]
valPart := strings . Split ( it . Value ( ) , "|" )
if len ( keyPart ) < 5 || len ( valPart ) < 2 {
continue
}
2013-08-04 02:54:30 +00:00
claimRef , ok := blob . Parse ( keyPart [ 4 ] )
if ! ok {
continue
}
baseRef , ok := blob . Parse ( keyPart [ 1 ] )
if ! ok {
2011-12-02 02:06:25 +00:00
continue
}
claimDate := unreverseTimeString ( keyPart [ 3 ] )
suffix := urld ( keyPart [ 2 ] )
2013-08-04 02:54:30 +00:00
target , ok := blob . Parse ( valPart [ 1 ] )
if ! ok {
continue
}
2011-12-02 02:06:25 +00:00
// TODO(bradfitz): investigate what's up with deleted
// forward path claims here. Needs docs with the
// interface too, and tests.
active := valPart [ 0 ]
_ = active
path := & search . Path {
Claim : claimRef ,
ClaimDate : claimDate ,
Base : baseRef ,
Suffix : suffix ,
Target : target ,
}
paths = append ( paths , path )
}
return
2011-11-02 01:37:27 +00:00
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) PathLookup ( signer , base blob . Ref , suffix string , at time . Time ) ( * search . Path , error ) {
2011-12-02 02:06:25 +00:00
paths , err := x . PathsLookup ( signer , base , suffix )
if err != nil {
return nil , err
}
var (
newest = int64 ( 0 )
atSeconds = int64 ( 0 )
best * search . Path
)
2012-02-20 12:32:46 +00:00
if ! at . IsZero ( ) {
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
atSeconds = at . Unix ( )
2011-12-02 02:06:25 +00:00
}
2012-02-20 12:32:46 +00:00
2011-12-02 02:06:25 +00:00
for _ , path := range paths {
2012-11-02 12:36:33 +00:00
t , err := time . Parse ( time . RFC3339 , path . ClaimDate )
2011-12-02 02:06:25 +00:00
if err != nil {
continue
}
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
secs := t . Unix ( )
2011-12-02 02:06:25 +00:00
if atSeconds != 0 && secs > atSeconds {
// Too new
continue
}
if newest > secs {
// Too old
continue
}
// Just right
newest , best = secs , path
}
if best == nil {
2012-02-20 12:32:46 +00:00
return nil , os . ErrNotExist
2011-12-02 02:06:25 +00:00
}
return best , nil
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) ExistingFileSchemas ( wholeRef blob . Ref ) ( schemaRefs [ ] blob . Ref , err error ) {
2011-12-03 19:26:42 +00:00
it := x . queryPrefix ( keyWholeToFileRef , wholeRef )
defer closeIterator ( it , & err )
for it . Next ( ) {
keyPart := strings . Split ( it . Key ( ) , "|" ) [ 1 : ]
if len ( keyPart ) < 2 {
continue
}
2013-08-04 02:54:30 +00:00
ref , ok := blob . Parse ( keyPart [ 1 ] )
if ok {
2011-12-03 19:26:42 +00:00
schemaRefs = append ( schemaRefs , ref )
}
}
return schemaRefs , nil
2011-12-03 16:05:34 +00:00
}
2013-02-19 05:31:41 +00:00
func ( x * Index ) loadKey ( key string , val * string , err * error , wg * sync . WaitGroup ) {
defer wg . Done ( )
* val , * err = x . s . Get ( key )
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) GetFileInfo ( fileRef blob . Ref ) ( * search . FileInfo , error ) {
2013-02-19 05:31:41 +00:00
ikey := "fileinfo|" + fileRef . String ( )
tkey := "filetimes|" + fileRef . String ( )
wg := new ( sync . WaitGroup )
wg . Add ( 2 )
var iv , tv string // info value, time value
var ierr , terr error
go x . loadKey ( ikey , & iv , & ierr , wg )
go x . loadKey ( tkey , & tv , & terr , wg )
wg . Wait ( )
if ierr == ErrNotFound {
2013-02-08 03:31:44 +00:00
go x . reindex ( fileRef ) // kinda a hack. Issue 103.
2012-02-20 12:32:46 +00:00
return nil , os . ErrNotExist
2011-12-03 21:56:05 +00:00
}
2013-02-19 05:31:41 +00:00
if ierr != nil {
return nil , ierr
}
if terr == ErrNotFound {
// Old index; retry. TODO: index versioning system.
x . reindex ( fileRef )
tv , terr = x . s . Get ( tkey )
}
valPart := strings . Split ( iv , "|" )
2011-12-03 21:56:05 +00:00
if len ( valPart ) < 3 {
2013-02-19 05:31:41 +00:00
log . Printf ( "index: bogus key %q = %q" , ikey , iv )
2012-02-20 12:32:46 +00:00
return nil , os . ErrNotExist
2011-12-03 21:56:05 +00:00
}
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
size , err := strconv . ParseInt ( valPart [ 0 ] , 10 , 64 )
2011-12-03 21:56:05 +00:00
if err != nil {
2013-02-19 05:31:41 +00:00
log . Printf ( "index: bogus integer at position 0 in key %q = %q" , ikey , iv )
2012-02-20 12:32:46 +00:00
return nil , os . ErrNotExist
2011-12-03 21:56:05 +00:00
}
2013-02-19 05:31:41 +00:00
fileName := urld ( valPart [ 1 ] )
2011-12-03 21:56:05 +00:00
fi := & search . FileInfo {
Size : size ,
2013-02-19 05:31:41 +00:00
FileName : fileName ,
2013-02-18 19:16:13 +00:00
MIMEType : urld ( valPart [ 2 ] ) ,
2011-12-03 21:56:05 +00:00
}
2013-02-19 05:31:41 +00:00
if tv != "" {
times := strings . Split ( urld ( tv ) , "," )
fi . Time = types . ParseTime3339OrZil ( times [ 0 ] )
if len ( times ) == 2 {
fi . ModTime = types . ParseTime3339OrZil ( times [ 1 ] )
}
}
2011-12-03 21:56:05 +00:00
return fi , nil
2011-12-03 16:05:34 +00:00
}
2012-02-26 12:49:03 +00:00
2013-08-04 02:54:30 +00:00
func ( x * Index ) GetImageInfo ( fileRef blob . Ref ) ( * search . ImageInfo , error ) {
2013-03-06 21:54:14 +00:00
// it might be that the key does not exist because image.DecodeConfig failed earlier
// (because of unsupported JPEG features like progressive mode).
key := keyImageSize . Key ( fileRef . String ( ) )
dim , err := x . s . Get ( key )
if err == ErrNotFound {
err = os . ErrNotExist
}
if err != nil {
return nil , err
}
valPart := strings . Split ( dim , "|" )
if len ( valPart ) != 2 {
return nil , fmt . Errorf ( "index: bogus key %q = %q" , key , dim )
}
width , err := strconv . Atoi ( valPart [ 0 ] )
if err != nil {
return nil , fmt . Errorf ( "index: bogus integer at position 0 in key %q: %q" , key , valPart [ 0 ] )
}
height , err := strconv . Atoi ( valPart [ 1 ] )
if err != nil {
return nil , fmt . Errorf ( "index: bogus integer at position 1 in key %q: %q" , key , valPart [ 1 ] )
}
imgInfo := & search . ImageInfo {
Width : width ,
Height : height ,
}
return imgInfo , nil
}
2013-08-04 02:54:30 +00:00
func ( x * Index ) EdgesTo ( ref blob . Ref , opts * search . EdgesToOpts ) ( edges [ ] * search . Edge , err error ) {
2012-11-05 09:29:42 +00:00
it := x . queryPrefix ( keyEdgeBackward , ref )
defer closeIterator ( it , & err )
2013-08-04 02:54:30 +00:00
permanodeParents := map [ string ] blob . Ref { } // blobref key => blobref set
2012-11-05 09:29:42 +00:00
for it . Next ( ) {
keyPart := strings . Split ( it . Key ( ) , "|" ) [ 1 : ]
if len ( keyPart ) < 2 {
continue
}
parent := keyPart [ 1 ]
2013-08-04 02:54:30 +00:00
parentRef , ok := blob . Parse ( parent )
if ! ok {
2012-11-05 09:29:42 +00:00
continue
}
valPart := strings . Split ( it . Value ( ) , "|" )
if len ( valPart ) < 2 {
continue
}
parentType , parentName := valPart [ 0 ] , valPart [ 1 ]
if parentType == "permanode" {
permanodeParents [ parent ] = parentRef
} else {
edges = append ( edges , & search . Edge {
From : parentRef ,
FromType : parentType ,
FromTitle : parentName ,
To : ref ,
} )
}
}
for _ , parentRef := range permanodeParents {
edges = append ( edges , & search . Edge {
2012-11-07 22:54:00 +00:00
From : parentRef ,
FromType : "permanode" ,
To : ref ,
} )
2012-11-05 09:29:42 +00:00
}
return edges , nil
2012-11-03 15:08:37 +00:00
}
2013-09-10 20:14:53 +00:00
// GetDirMembers sends on dest the children of the static directory dir.
2013-09-12 13:25:31 +00:00
func ( x * Index ) GetDirMembers ( dir blob . Ref , dest chan <- blob . Ref , limit int ) ( err error ) {
2013-09-10 20:14:53 +00:00
defer close ( dest )
sent := 0
it := x . queryPrefix ( keyStaticDirChild , dir . String ( ) )
2013-09-12 13:25:31 +00:00
defer closeIterator ( it , & err )
2013-09-10 20:14:53 +00:00
for it . Next ( ) {
keyPart := strings . Split ( it . Key ( ) , "|" )
if len ( keyPart ) != 3 {
return fmt . Errorf ( "index: bogus key keyStaticDirChild = %q" , it . Key ( ) )
}
child , ok := blob . Parse ( keyPart [ 2 ] )
if ! ok {
continue
}
dest <- child
sent ++
if sent == limit {
break
}
}
return nil
}
2013-10-19 00:17:35 +00:00
// EnumerateBlobMeta sends all metadata about all known blobs to ch and then closes ch.
func ( x * Index ) EnumerateBlobMeta ( ch chan <- search . BlobMeta ) ( err error ) {
defer close ( ch )
it := x . queryPrefixString ( "meta:" )
defer closeIterator ( it , & err )
for it . Next ( ) {
refStr := strings . TrimPrefix ( it . Key ( ) , "meta:" )
br , ok := blob . Parse ( refStr )
if ! ok {
continue
}
v := it . Value ( )
pipe := strings . Index ( v , "|" )
if pipe < 0 {
continue
}
size , err := strconv . Atoi ( v [ : pipe ] )
if err != nil {
continue
}
ch <- search . BlobMeta {
Ref : br ,
Size : size ,
MIMEType : v [ pipe + 1 : ] ,
}
}
return err
}
2013-08-27 02:07:28 +00:00
// Storage returns the index's underlying Storage implementation.
2013-01-14 04:19:36 +00:00
func ( x * Index ) Storage ( ) Storage { return x . s }
2013-08-27 02:07:28 +00:00
// Close closes the underlying Storage, if the storage has a Close method.
// The return value is the return value of the underlying Close, or
// nil otherwise.
func ( x * Index ) Close ( ) error {
if cl , ok := x . s . ( io . Closer ) ; ok {
return cl . Close ( )
}
return nil
}