Skip to content

Commit

Permalink
Merge pull request #300 from teharrison/master
Browse files Browse the repository at this point in the history
minor fixes, features
  • Loading branch information
teharrison committed Feb 4, 2016
2 parents ee8f71d + ca68626 commit 7b3162b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
7 changes: 7 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.9.14

- add versioning to indexes
- option to clear revisions array in node
- fix duplicate additions to revision array
- explicit check for bson document max size upon save, return meaningful error

# v0.9.13

- added option to copy attributes when doing node copy
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.13
0.9.14
3 changes: 3 additions & 0 deletions shock-server/node/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"strings"
)

// mongodb has hard limit of 16 MB docuemnt size
var DocumentMaxByte = 16777216

// Initialize creates a copy of the mongodb connection and then uses that connection to
// create the Nodes collection in mongodb. Then, it ensures that there is a unique index
// on the id key in this collection, creating the index if necessary.
Expand Down
7 changes: 7 additions & 0 deletions shock-server/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ func (node *Node) RemoveExpiration() (err error) {
return
}

func (node *Node) ClearRevisions() (err error) {
// empty the revisions array
node.Revisions = nil
err = node.Save()
return
}

func (node *Node) SetAttributes(attr FormFile) (err error) {
defer attr.Remove()
attributes, err := ioutil.ReadFile(attr.Path)
Expand Down
24 changes: 19 additions & 5 deletions shock-server/node/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ func (node *Node) Update(params map[string]string, files FormFiles) (err error)
}
}

// clear node revisions
if _, hasClearRevisions := params["clear_revisions"]; hasClearRevisions {
if err = node.ClearRevisions(); err != nil {
return err
}
}

// handle part file / we do a node level lock here
if hasPartsFile {
if node.HasFile() {
Expand Down Expand Up @@ -438,8 +445,11 @@ func (node *Node) Update(params map[string]string, files FormFiles) (err error)
}

func (node *Node) Save() (err error) {
// update versions
previousVersion := node.Version
node.UpdateVersion()
if len(node.Revisions) == 0 || node.Revisions[len(node.Revisions)-1].Version != node.Version {
// only add to revisions if not new and has changed
if previousVersion != "" && previousVersion != node.Version {
n := Node{node.Id, node.Version, node.File, node.Attributes, node.Indexes, node.Acl, node.VersionParts, node.Tags, nil, node.Linkages, node.CreatedOn, node.LastModified, node.Expiration, node.Type, node.Subset, node.Parts}
node.Revisions = append(node.Revisions, n)
}
Expand All @@ -448,17 +458,21 @@ func (node *Node) Save() (err error) {
} else {
node.LastModified = time.Now()
}

bsonPath := fmt.Sprintf("%s/%s.bson", node.Path(), node.Id)
os.Remove(bsonPath)
// get bson, test size and print
nbson, err := bson.Marshal(node)
if err != nil {
return
}
if len(nbson) >= DocumentMaxByte {
return errors.New(fmt.Sprintf("bson document size is greater than limit of %d bytes", DocumentMaxByte))
}
bsonPath := fmt.Sprintf("%s/%s.bson", node.Path(), node.Id)
os.Remove(bsonPath)
err = ioutil.WriteFile(bsonPath, nbson, 0644)
if err != nil {
return
}
// save node to mongodb
err = dbUpsert(node)
if err != nil {
return
Expand All @@ -470,7 +484,7 @@ func (node *Node) UpdateVersion() (err error) {
parts := make(map[string]string)
h := md5.New()
version := node.Id
for name, value := range map[string]interface{}{"file_ver": node.File, "attributes_ver": node.Attributes, "acl_ver": node.Acl} {
for name, value := range map[string]interface{}{"file_ver": node.File, "indexes_ver": node.Indexes, "attributes_ver": node.Attributes, "acl_ver": node.Acl} {
m, er := json.Marshal(value)
if er != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion shock-server/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"

// Arrays to check for valid param and file form names for node creation and updating, and also acl modification.
// Note: indexing and querying do not use functions that use these arrays and thus we don't have to include those field names.
var validParams = []string{"action", "all", "archive_format", "attributes_str", "copy_attributes", "copy_data", "copy_indexes", "compression", "delete", "expiration", "file_name", "format", "ids", "index_name", "linkage", "operation", "owner", "parent_index", "parent_node", "parts", "path", "preserve_acls", "read", "remove_expiration", "source", "tags", "type", "unpack_node", "users", "write"}
var validParams = []string{"action", "all", "archive_format", "attributes_str", "clear_revisions", "copy_attributes", "copy_data", "copy_indexes", "compression", "delete", "expiration", "file_name", "format", "ids", "index_name", "linkage", "operation", "owner", "parent_index", "parent_node", "parts", "path", "preserve_acls", "read", "remove_expiration", "source", "tags", "type", "unpack_node", "users", "write"}
var validFiles = []string{"attributes", "subset_indices", "upload", "gzip", "bzip2"}
var ValidUpload = []string{"upload", "gzip", "bzip2"}

Expand Down

0 comments on commit 7b3162b

Please sign in to comment.