Package com.sleepycat.je.dbi

Examples of com.sleepycat.je.dbi.MemoryBudget


        checkpointId++;
        nCheckpoints++;
        boolean success = false;
        boolean traced = false;
        int dirtyMapMemSize = 0;
        MemoryBudget mb = envImpl.getMemoryBudget();
        try {

      /*
       * Eviction can run during checkpoint as long as it follows the
       * same rules for using provisional logging and for propagating
       * logging of the checkpoint dirty set up the tree. We have to lock
       * out the evictor after the logging of checkpoint start until
       * we've selected the dirty set and decided on the highest level to
       * be flushed. See SR 11163, 11349.
       */
      long checkpointStart = DbLsn.NULL_LSN;
      long firstActiveLsn = DbLsn.NULL_LSN;
      SortedMap dirtyMap = null;
      synchronized (envImpl.getEvictor()) {
    /* Log the checkpoint start. */
    CheckpointStart startEntry =
        new CheckpointStart(checkpointId, invokingSource);
    checkpointStart = logManager.log(startEntry);

    /*
     * Remember the first active LSN -- before this position in the
     * log, there are no active transactions at this point in time.
     */
    firstActiveLsn = envImpl.getTxnManager().getFirstActiveLsn();

    if (firstActiveLsn == DbLsn.NULL_LSN) {
        firstActiveLsn = checkpointStart;
    } else {
        if (DbLsn.compareTo(checkpointStart, firstActiveLsn) < 0) {
      firstActiveLsn = checkpointStart;
        }
    }
    /* Find the dirty set. */
    dirtyMap = selectDirtyINs(flushAll, flushExtraLevel);
      }

            /* Add each level's references to the budget. */
      int totalSize = 0;
            for (Iterator i = dirtyMap.values().iterator(); i.hasNext();) {
                Set nodeSet = (Set) i.next();
                int size = nodeSet.size() *
                    MemoryBudget.CHECKPOINT_REFERENCE_SIZE;
    totalSize += size;
                dirtyMapMemSize += size;
            }
      mb.updateMiscMemoryUsage(totalSize);

            /* Flush IN nodes. */
            boolean allowDeltas = !config.getMinimizeRecoveryTime();
            flushDirtyNodes(dirtyMap, flushAll, allowDeltas,
                            flushExtraLevel, checkpointStart);

            /*
             * Flush utilization info AFTER flushing IN nodes to reduce the
             * inaccuracies caused by the sequence FileSummaryLN-LN-BIN.
             */
            flushUtilizationInfo();

            CheckpointEnd endEntry =
                new CheckpointEnd(invokingSource,
                                  checkpointStart,
                                  envImpl.getRootLsn(),
                                  firstActiveLsn,
                                  Node.getLastId(),
                                  envImpl.getDbMapTree().getLastDbId(),
                                  envImpl.getTxnManager().getLastTxnId(),
                                  checkpointId);

            /*
             * Log checkpoint end and update state kept about the last
             * checkpoint location. Send a trace message *before* the
             * checkpoint end log entry. This is done so that the normal trace
             * message doesn't affect the time-based isRunnable() calculation,
             * which only issues a checkpoint if a log record has been written
             * since the last checkpoint.
             */
            trace(envImpl, invokingSource, true);
            traced = true;

            /*
             * Always flush to ensure that cleaned files are not referenced,
             * and to ensure that this checkpoint is not wasted if we crash.
             */
            lastCheckpointEnd =
              logManager.logForceFlush(endEntry,
                                  true); // fsync required
            lastFirstActiveLsn = firstActiveLsn;
            lastCheckpointStart = checkpointStart;

      /*
       * Reset the highestFlushLevel so evictor activity knows there's no
       * further requirement for provisional logging. SR 11163.
       */
      highestFlushLevel = IN.MIN_LEVEL;

            success = true;

            if (cleanerFiles != null) {
                cleaner.updateFilesAtCheckpointEnd(cleanerFiles);
            }
        } catch (DatabaseException e) {
            Tracer.trace(envImpl, "Checkpointer", "doCheckpoint",
                         "checkpointId=" + checkpointId, e);
            throw e;
        } finally {
            mb.updateMiscMemoryUsage(0 - dirtyMapMemSize);
            if (!traced) {
                trace(envImpl, invokingSource, success);
            }
        }
    }
View Full Code Here


   * the best in terms of encapsulation as prefereably all memory
   * calculations are done in MemoryBudget, but done this way to avoid
   * any extra latching.
   */
        long totalSize = 0;
        MemoryBudget mb = envImpl.getMemoryBudget();

        try {
            Iterator iter = inMemINs.iterator();
            while (iter.hasNext()) {
                IN in = (IN) iter.next();
                in.latch(false);
                try {
                    totalSize = mb.accumulateNewUsage(in, totalSize);

                    if (in.getDirty()) {
                        Integer level = new Integer(in.getLevel());
                        Set dirtySet;
                        if (newDirtyMap.containsKey(level)) {
                            dirtySet = (Set) newDirtyMap.get(level);
                        } else {
                            dirtySet = new HashSet();
                            newDirtyMap.put(level, dirtySet);
                        }
                        dirtySet.add
                             (new CheckpointReference(in.getDatabase(),
                                                      in.getNodeId(),
                                                      in.containsDuplicates(),
                                                      in.isDbRoot(),
                                                      in.getMainTreeKey(),
                                                      in.getDupTreeKey()));
                    }
                } finally {
                    in.releaseLatch();
                }
            }

            /* Set the tree cache size. */
            mb.refreshTreeMemoryUsage(totalSize);

            /*
             * If we're flushing all for cleaning, we must flush to the point
             * that there are no nodes with LSNs in the cleaned files.
             */
 
View Full Code Here

         */
        if (!env.isOpen()) {
            return 0;
        }

        MemoryBudget mb = env.getMemoryBudget();
        long totalEvicted = 0;
        long totalBytes = 0;
        int largestBytes = 0;
        TrackedFileSummary bestFile = null;

        /*
         * Use a local variable to access the array since the snapshot
         * field can be changed by other threads.
         */
        TrackedFileSummary[] a = snapshot;
        for (int i = 0; i < a.length; i += 1) {

            TrackedFileSummary tfs = a[i];
            int mem = tfs.getMemorySize();
            totalBytes += mem;

            if (mem > largestBytes && tfs.getAllowFlush()) {
                largestBytes = mem;
                bestFile = tfs;
            }
        }

        if (bestFile != null && totalBytes > mb.getTrackerBudget()) {
            env.getUtilizationProfile().flushFileSummary(bestFile);
            totalEvicted += largestBytes;
        }
        return totalEvicted;
    }
View Full Code Here

     */
    public synchronized void clearCache() {

        int memorySize = fileSummaryMap.size() *
            MemoryBudget.UTILIZATION_PROFILE_ENTRY;
        MemoryBudget mb = env.getMemoryBudget();
        mb.updateMiscMemoryUsage(0 - memorySize);

        fileSummaryMap = new TreeMap();
        cachePopulated = false;
    }
View Full Code Here

        synchronized (this) {
            assert cachePopulated;

            /* Remove from the cache. */
            if (fileSummaryMap.remove(fileNum) != null) {
                MemoryBudget mb = env.getMemoryBudget();
                mb.updateMiscMemoryUsage
                    (0 - MemoryBudget.UTILIZATION_PROFILE_ENTRY);
            }
        }

        /* Do not synchronize during LN deletion, to permit eviction. */
 
View Full Code Here

        insertFileSummary(ln, fileNum, sequence);

        /* Cache the updated summary object.  */
        summary = ln.getBaseSummary();
        if (fileSummaryMap.put(fileNumLong, summary) == null) {
            MemoryBudget mb = env.getMemoryBudget();
            mb.updateMiscMemoryUsage
                (MemoryBudget.UTILIZATION_PROFILE_ENTRY);
        }

        return ln.getObsoleteOffsets();
    }
View Full Code Here

                locker.operationEnd();
            }

            int newMemorySize = fileSummaryMap.size() *
                MemoryBudget.UTILIZATION_PROFILE_ENTRY;
            MemoryBudget mb = env.getMemoryBudget();
            mb.updateMiscMemoryUsage(newMemorySize - oldMemorySize);
        }

        cachePopulated = true;
        return true;
    }
View Full Code Here

     * Count up the memory usage attributable to this node alone. LNs children
     * are counted by their BIN/DIN parents, but INs are not counted by their
     * parents because they are resident on the IN list.
     */
    protected long computeMemorySize() {
        MemoryBudget mb = databaseImpl.getDbEnvironment().getMemoryBudget();
        long calcMemorySize = getMemoryOverhead(mb);
  calcMemorySize += computeLsnOverhead();
        for (int i = 0; i < nEntries; i++) {
            calcMemorySize += getEntryInMemorySize(i);
        }
View Full Code Here

         * on the IN list. For example, when we create new INs, they are
         * manipulated off the IN list before being added; if we updated the
         * environment wide cache then, we'd end up double counting.
         */
        if (inListResident) {
            MemoryBudget mb =
                databaseImpl.getDbEnvironment().getMemoryBudget();

      accumulatedDelta += delta;
      if (accumulatedDelta > ACCUMULATED_LIMIT ||
    accumulatedDelta < -ACCUMULATED_LIMIT) {
    mb.updateTreeMemoryUsage(accumulatedDelta);
    accumulatedDelta = 0;
      }
        }
    }
View Full Code Here

    int getNumLevels() {
        return levelMap.size();
    }

    void addCostToMemoryBudget() {
        MemoryBudget mb = envImpl.getMemoryBudget();
        int cost = numEntries * MemoryBudget.CHECKPOINT_REFERENCE_SIZE;
        mb.updateAdminMemoryUsage(cost);
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.dbi.MemoryBudget

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.