Search in sources :

Example 1 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class SystemAdmin method compactAllDiskStores.

public static void compactAllDiskStores(List args) throws AdminException {
    InternalDistributedSystem ads = getAdminCnx();
    Map<DistributedMember, Set<PersistentID>> status = AdminDistributedSystemImpl.compactAllDiskStores(ads.getDistributionManager());
    System.out.println("Compaction complete.");
    System.out.println("The following disk stores compacted some files:");
    for (Set<PersistentID> memberStores : status.values()) {
        for (PersistentID store : memberStores) {
            System.out.println("\t" + store);
        }
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 2 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class SystemAdmin method backup.

public static void backup(String targetDir) throws AdminException {
    InternalDistributedSystem ads = getAdminCnx();
    // Baseline directory should be null if it was not provided on the command line
    BackupStatus status = AdminDistributedSystemImpl.backupAllMembers(ads.getDistributionManager(), new File(targetDir), (SystemAdmin.baselineDir == null ? null : new File(SystemAdmin.baselineDir)));
    boolean incomplete = !status.getOfflineDiskStores().isEmpty();
    System.out.println("The following disk stores were backed up:");
    for (Set<PersistentID> memberStores : status.getBackedUpDiskStores().values()) {
        for (PersistentID store : memberStores) {
            System.out.println("\t" + store);
        }
    }
    if (incomplete) {
        System.err.println("The backup may be incomplete. The following disk stores are not online:");
        for (PersistentID store : status.getOfflineDiskStores()) {
            System.err.println("\t" + store);
        }
    } else {
        System.out.println("Backup successful.");
    }
}
Also used : BackupStatus(org.apache.geode.admin.BackupStatus) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 3 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class MemberMBeanBridge method backupMember.

/**
   * backs up all the disk to the targeted directory
   * 
   * @param targetDirPath path of the directory where back up is to be taken
   * @return array of DiskBackup results which might get aggregated at Managing node Check the
   *         validity of this mbean call. When does it make sense to backup a single member of a
   *         gemfire system in isolation of the other members?
   */
public DiskBackupResult[] backupMember(String targetDirPath) {
    if (cache != null) {
        Collection<DiskStore> diskStores = cache.listDiskStoresIncludingRegionOwned();
        for (DiskStore store : diskStores) {
            store.flush();
        }
    }
    DiskBackupResult[] diskBackUpResult = null;
    File targetDir = new File(targetDirPath);
    if (cache == null) {
        return null;
    } else {
        try {
            BackupManager manager = cache.startBackup(cache.getInternalDistributedSystem().getDistributedMember());
            boolean abort = true;
            Set<PersistentID> existingDataStores;
            Set<PersistentID> successfulDataStores;
            try {
                existingDataStores = manager.prepareBackup();
                abort = false;
            } finally {
                successfulDataStores = manager.finishBackup(targetDir, null, /* TODO rishi */
                abort);
            }
            diskBackUpResult = new DiskBackupResult[existingDataStores.size()];
            int j = 0;
            for (PersistentID id : existingDataStores) {
                if (successfulDataStores.contains(id)) {
                    diskBackUpResult[j] = new DiskBackupResult(id.getDirectory(), false);
                } else {
                    diskBackUpResult[j] = new DiskBackupResult(id.getDirectory(), true);
                }
                j++;
            }
        } catch (IOException e) {
            throw new ManagementException(e);
        }
    }
    return diskBackUpResult;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) DiskBackupResult(org.apache.geode.management.DiskBackupResult) ManagementException(org.apache.geode.management.ManagementException) IOException(java.io.IOException) File(java.io.File) BackupManager(org.apache.geode.internal.cache.persistence.BackupManager) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 4 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class DistributedSystemBridge method backupAllMembers.

/**
   *
   * @param targetDirPath path of the directory where the back up files should be placed.
   * @param baselineDirPath path of the directory for baseline backup.
   * @return open type DiskBackupStatus containing each member wise disk back up status
   */
public DiskBackupStatus backupAllMembers(String targetDirPath, String baselineDirPath) throws Exception {
    if (BackupDataStoreHelper.obtainLock(dm)) {
        try {
            if (targetDirPath == null || targetDirPath.isEmpty()) {
                throw new Exception(ManagementStrings.TARGET_DIR_CANT_BE_NULL_OR_EMPTY.toLocalizedString());
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
            File targetDir = new File(targetDirPath);
            targetDir = new File(targetDir, format.format(new Date()));
            File baselineDir = null;
            if (baselineDirPath != null) {
                baselineDir = new File(baselineDirPath);
            }
            DM dm = cache.getDistributionManager();
            Set<PersistentID> missingMembers = MissingPersistentIDsRequest.send(dm);
            Set recipients = dm.getOtherDistributionManagerIds();
            BackupDataStoreResult result = BackupDataStoreHelper.backupAllMembers(dm, recipients, targetDir, baselineDir);
            Iterator<DistributedMember> it = result.getSuccessfulMembers().keySet().iterator();
            Map<String, String[]> backedUpDiskStores = new HashMap<>();
            while (it.hasNext()) {
                DistributedMember member = it.next();
                Set<PersistentID> setOfDisk = result.getSuccessfulMembers().get(member);
                String[] setOfDiskStr = new String[setOfDisk.size()];
                int j = 0;
                for (PersistentID id : setOfDisk) {
                    setOfDiskStr[j] = id.getDirectory();
                    j++;
                }
                backedUpDiskStores.put(member.getId(), setOfDiskStr);
            }
            // should override the previous missingMembers
            for (Set<PersistentID> onlineMembersIds : result.getSuccessfulMembers().values()) {
                missingMembers.removeAll(onlineMembersIds);
            }
            result.getExistingDataStores().keySet().removeAll(result.getSuccessfulMembers().keySet());
            String[] setOfMissingDiskStr = null;
            if (result.getExistingDataStores().size() > 0) {
                setOfMissingDiskStr = new String[result.getExistingDataStores().size()];
                int j = 0;
                for (Set<PersistentID> lostMembersIds : result.getExistingDataStores().values()) {
                    for (PersistentID id : lostMembersIds) {
                        setOfMissingDiskStr[j] = id.getDirectory();
                        j++;
                    }
                }
            }
            DiskBackupStatus diskBackupStatus = new DiskBackupStatus();
            diskBackupStatus.setBackedUpDiskStores(backedUpDiskStores);
            diskBackupStatus.setOfflineDiskStores(setOfMissingDiskStr);
            return diskBackupStatus;
        } finally {
            BackupDataStoreHelper.releaseLock(dm);
        }
    } else {
        throw new Exception(LocalizedStrings.DistributedSystem_BACKUP_ALREADY_IN_PROGRESS.toLocalizedString());
    }
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BackupDataStoreResult(org.apache.geode.admin.internal.BackupDataStoreResult) DM(org.apache.geode.distributed.internal.DM) ManagementException(org.apache.geode.management.ManagementException) ListenerNotFoundException(javax.management.ListenerNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) Date(java.util.Date) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) PersistentID(org.apache.geode.cache.persistence.PersistentID) DiskBackupStatus(org.apache.geode.management.DiskBackupStatus)

Example 5 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class MissingPersistentIDsRequest method createResponse.

@Override
protected AdminResponse createResponse(DistributionManager dm) {
    Set<PersistentID> missingIds = new HashSet<>();
    Set<PersistentID> localPatterns = new HashSet<>();
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && !cache.isClosed()) {
        PersistentMemberManager mm = cache.getPersistentMemberManager();
        Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
        for (Map.Entry<String, Set<PersistentMemberID>> entry : waitingRegions.entrySet()) {
            for (PersistentMemberID id : entry.getValue()) {
                missingIds.add(new PersistentMemberPattern(id));
            }
        }
        Set<PersistentMemberID> localIds = mm.getPersistentIDs();
        for (PersistentMemberID id : localIds) {
            localPatterns.add(new PersistentMemberPattern(id));
        }
    }
    return new MissingPersistentIDsResponse(missingIds, localPatterns, this.getSender());
}
Also used : PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) InternalCache(org.apache.geode.internal.cache.InternalCache) PersistentMemberID(org.apache.geode.internal.cache.persistence.PersistentMemberID) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) Map(java.util.Map) HashSet(java.util.HashSet) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Aggregations

PersistentID (org.apache.geode.cache.persistence.PersistentID)29 HashSet (java.util.HashSet)11 File (java.io.File)8 Set (java.util.Set)8 IOException (java.io.IOException)7 DiskStore (org.apache.geode.cache.DiskStore)7 InternalCache (org.apache.geode.internal.cache.InternalCache)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 DistributedMember (org.apache.geode.distributed.DistributedMember)5 Map (java.util.Map)4 AdminException (org.apache.geode.admin.AdminException)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 LinkedList (java.util.LinkedList)3 TreeSet (java.util.TreeSet)3 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)3 AdminDistributedSystem (org.apache.geode.admin.AdminDistributedSystem)3 BackupStatus (org.apache.geode.admin.BackupStatus)3 DistributedSystemConfig (org.apache.geode.admin.DistributedSystemConfig)3