Package de.fhg.igd.mongomvcc.impl.internal

Examples of de.fhg.igd.mongomvcc.impl.internal.Commit


 
  /**
   * @return the thread-local head of this branch
   */
  private Commit getHeadCommit() {
    Commit r = _head.get();
    if (r == null) {
      if (_name != null) {
        r = _tree.resolveBranch(_name);
      } else {
        r = _tree.resolveCommit(_rootCid);
View Full Code Here


  @Override
  public long commit() {
    Index idx = getIndex();
    //clone dirty objects because we clear them below
    Map<String, IdMap> dos = new HashMap<String, IdMap>(idx.getDirtyObjects());
    Commit head = getHeadCommit();
    Commit c = new Commit(_db.getCounter().getNextId(), head.getCID(), _rootCid, dos);
    _tree.addCommit(c);
    updateHead(c);
   
    //mark deleted objects as deleted in the database
    DB db = _db.getDB();
    String lifetimeAttr = MongoDBConstants.LIFETIME + "." + getRootCid();
    for (Map.Entry<String, IdSet> e : idx.getDeletedOids().entrySet()) {
      DBCollection dbc = db.getCollection(e.getKey());
      IdSetIterator li = e.getValue().iterator();
      while (li.hasNext()) {
        long oid = li.next();
        //save the CID of the commit where the object has been deleted
        dbc.update(new BasicDBObject(MongoDBConstants.ID, oid), new BasicDBObject("$set",
            new BasicDBObject(lifetimeAttr, head.getCID())));
      }
    }
   
    //mark dirty objects as inserted
    String instimeAttr = MongoDBConstants.LIFETIME + ".i" + getRootCid();
    for (Map.Entry<String, IdMap> e : dos.entrySet()) {
      DBCollection dbc = db.getCollection(e.getKey());
      IdMap m = e.getValue();
      IdMapIterator li = m.iterator();
      while (li.hasNext()) {
        li.advance();
        long oid = li.value();
        if (oid == -1) {
          //the document has been inserted and then deleted again
          //do not save time of insertion
          continue;
        }
        //save the CID of the commit where the object has been inserted
        dbc.update(new BasicDBObject(MongoDBConstants.ID, oid), new BasicDBObject("$set",
            new BasicDBObject(instimeAttr, head.getCID())));
      }
    }
   
    //reset index
    idx.clearDirtyObjects();
   
    //if we fail below, the commit has already been performed and the
    //index is clear. failing below simply means the named branch's
    //head could not be updated. If the caller wants to keep the commit
    //he/she just has to create a new named branch based on this
    //branch's head.
   
    //update named branch's head
    if (_name != null) {
      //synchronize the following part, because we first resolve the branch
      //and then update it
      synchronized (this) {
        //check for conflicts (i.e. if another thread has already updated the branch's head)
        if (_tree.resolveBranch(_name).getCID() != c.getParentCID()) {
          throw new VException("Branch " + _name + " has already been " +
              "updated by another commit");
        }
        _tree.updateBranchHead(_name, c.getCID());
      }
    }

    return c.getCID();
  }
View Full Code Here

    _counter = new MongoDBVCounter(_db);
    _tree = new Tree(_db);
   
    //create root commit and master branch if needed
    if (_tree.isEmpty()) {
      Commit root = new Commit(_counter.getNextId(), 0, 0,
          Collections.<String, IdMap>emptyMap());
      _tree.addCommit(root);
      _tree.addBranch(VConstants.MASTER, root.getCID());
    }
  }
View Full Code Here

   * branch and so the commit's root ID will be returned.
   * @param cid the CID of the commit to branch from
   * @return the root CID for the new branch
   */
  private long determineRootForBranch(long cid) {
    Commit head = _tree.resolveCommit(cid);
    long root = head.getRootCID();
    if (_tree.existsBranch(root) || _tree.hasChildren(cid)) {
      //we're trying to create a branch from a commit that belongs
      //to an existing branch. create a new branch from here on.
      root = cid;
    }
View Full Code Here

    }
   
    //iterate through all commits and eliminate referenced documents
    DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
    for (DBObject o : collCommits.find()) {
      Commit c = Tree.deserializeCommit(o);
      Map<String, IdMap> allObjs = c.getObjects();
      IdMap objs = allObjs.get(collection);
      if (objs != null) {
        //eliminate OIDs referenced by this commit
        IdMapIterator mi = objs.iterator();
        while (mi.hasNext()) {
View Full Code Here

TOP

Related Classes of de.fhg.igd.mongomvcc.impl.internal.Commit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.