Package org.xtreemfs.babudb.api.exception

Examples of org.xtreemfs.babudb.api.exception.BabuDBException


    }
   
    public static void initiateConversion(int dbVer, final BabuDBConfig cfg) throws BabuDBException {
       
        if (!DBWriter.checkVersionSupport(dbVer))
            throw new BabuDBException(ErrorCode.IO_ERROR, "on-disk format (version " + dbVer
                + ") is incompatible with this BabuDB release (version " + BABUDB_DB_FORMAT_VERSION
                + "); no automatic conversion possible");
       
        else
            Logging
                    .logMessage(Logging.LEVEL_INFO, Category.storage, (Object) null,
                        "starting database conversion");
       
        final File dbDir = new File(cfg.getBaseDir());
        final File dbLogDir = new File(cfg.getDbLogDir());
        final File targetDir = new File(dbDir, ".conversion");
        final File cfgFile = new File(dbDir, cfg.getDbCfgFile());
        final File backupDir = new File(cfg.getBaseDir(), ".backup-" + dbVer);
        final File backupDBDir = new File(backupDir, "database");
        final File backupLogDir = new File(backupDir, "db-log");
       
        if (targetDir.exists())
            FSUtils.delTree(targetDir);
       
        try {
           
            // write version independent database representation
            DBWriter.writeDB(cfg, dbVer, targetDir.getAbsolutePath());
           
            // move everything except for the temporary dump and the config file
            // to a backup directory
            File[] dbFilesToMove = dbDir.listFiles(new FileFilter() {
                public boolean accept(File pathname) {
                    return !(pathname.equals(targetDir) || pathname.equals(cfgFile) || pathname
                            .equals(backupDir) || pathname.equals(dbLogDir));
                }
            });
           
            File[] logFilesToMove = dbLogDir.equals(dbDir) ? new File[0] : dbLogDir.listFiles();
           
            backupDBDir.mkdirs();
            backupLogDir.mkdirs();
            if (backupDBDir.exists() && backupLogDir.exists()) {
                // move all files to a backup directory
                for (File f : dbFilesToMove)
                    if (!f.renameTo(new File(backupDBDir, f.getName())))
                        throw new BabuDBException(ErrorCode.IO_ERROR,
                            "an error occurred while trying to convert the database: '" + f.getAbsolutePath()
                                + "' could not be moved");
               
                for (File f : logFilesToMove)
                    if (!f.renameTo(new File(backupLogDir, f.getName())))
                        throw new BabuDBException(ErrorCode.IO_ERROR,
                            "an error occurred while trying to convert the database: '" + f.getAbsolutePath()
                                + "' could not be moved");
               
            } else
                throw new BabuDBException(ErrorCode.IO_ERROR,
                    "an error occurred while trying to convert the database: backup directory could not be created");
           
            // copy the config file to the backup directory
            FSUtils.copyTree(cfgFile, new File(backupDir, cfgFile.getName()));
           
        } catch (IOException exc) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "an error occurred while trying to convert the database", exc);
        }
       
    }
View Full Code Here


                   
                    IndexFileIterator it = new IndexFileIterator(indexFile);
                    while (it.hasNext()) {
                        Entry<byte[], byte[]> next = it.next();
                        if (next == null) {
                            throw new BabuDBException(ErrorCode.INTERNAL_ERROR,
                                "database conversion failed, dump corrupted");
                        }
                       
                        db.singleInsert(indexId, next.getKey(), next.getValue(), null).get();
                    }
                   
                    it.destroy();
                }
               
                // retrieve all nested snapshot directories
                File snapRootDir = new File(dbDir, DBWriter.SNAPSHOT_DIR_NAME);
                File[] snapDirs = snapRootDir.listFiles();
                if (snapDirs == null)
                    continue;
               
                // for each snapshot directory ...
                for (File snapDir : snapDirs) {
                   
                    // TODO: restore snapshots
                   
                }
            }
           
        } catch (IOException exc) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "an error has occurred while trying to convert the database", exc);
        }
       
        // delete the version-independent dump
        FSUtils.delTree(targetDir);
View Full Code Here

                    trees.add(new LSMTree(null, comparators[i], this.compression, maxEntriesPerBlock,
                        maxBlockFileSize, !disableMMap, mmapLimit));
                }
                ondiskLSN = NO_DB_LSN;
            } catch (IOException ex) {
                throw new BabuDBException(ErrorCode.IO_ERROR, "cannot create new index", ex);
            }
        }
    }
View Full Code Here

                public boolean accept(File dir, String name) {
                    return name.startsWith("IX" + idx + "V");
                }
            });
            if (files == null)
                throw new BabuDBException(ErrorCode.IO_ERROR, "database directory '" + databaseDir
                    + "' does not exist");
           
            int maxView = -1;
            long maxSeq = -1;
            Pattern p = Pattern.compile(SNAPSHOT_FILENAME_REGEXP);
            for (String fname : files) {
                Matcher m = p.matcher(fname);
                m.matches();
                Logging.logMessage(Logging.LEVEL_DEBUG, this, "inspecting snapshot: " + fname);
               
                int view = Integer.valueOf(m.group(2));
                long seq = Long.valueOf(m.group(3));
                if (view > maxView) {
                    maxView = view;
                    maxSeq = seq;
                } else if (view == maxView) {
                    if (seq > maxSeq)
                        maxSeq = seq;
                }
            }
            // load max
            try {
                if (maxView > -1) {
                    Logging.logMessage(Logging.LEVEL_DEBUG, this, "loading database " + this.databaseName
                        + " from latest snapshot:" + databaseDir + File.separator + "IX" + index + "V"
                        + maxView + "SEQ" + maxSeq);
                    assert (comparators[index] != null);
                    trees.set(index, new LSMTree(databaseDir + File.separator
                        + getSnapshotFilename(index, maxView, maxSeq), comparators[index], this.compression,
                        this.maxEntriesPerBlock, this.maxBlockFileSize, !this.disableMMap, this.mmapLimit));
                    ondiskLSN = new LSN(maxView, maxSeq);
                } else {
                    ondiskLSN = NO_DB_LSN;
                    Logging.logMessage(Logging.LEVEL_DEBUG, this, "no snapshot for database "
                        + this.databaseName);
                    assert (comparators[index] != null);
                    trees.set(index, new LSMTree(null, comparators[index], this.compression,
                        this.maxEntriesPerBlock, this.maxBlockFileSize, !this.disableMMap, this.mmapLimit));
                }
            } catch (IOException ex) {
                Logging.logError(Logging.LEVEL_ERROR, this, ex);
                throw new BabuDBException(ErrorCode.IO_ERROR, "cannot load index from disk", ex);
            }
        }
    }
View Full Code Here

                    assert (graceful || entries.size() == 0);
                   
                    // clear pending requests, if available
                    for (LogEntry le : entries) {
                        le.free();
                        le.getListener().failed(new BabuDBException(
                                ErrorCode.INTERRUPTED, "DiskLogger was shut down, before the " +
                                "entry could be written to the log-file"));
                    }
                }
            }
View Full Code Here

            List<Integer> ids = new LinkedList<Integer>();
            if (configFile.exists()) {
                ois = new ObjectInputStream(new FileInputStream(configFile));
                final int dbFormatVer = ois.readInt();
                if (dbFormatVer != BABUDB_DB_FORMAT_VERSION) {
                    throw new BabuDBException(ErrorCode.IO_ERROR, "on-disk format (version " + dbFormatVer
                        + ") is incompatible with this BabuDB release " + "(uses on-disk format version "
                        + BABUDB_DB_FORMAT_VERSION + ")");
                }
                final int numDB = ois.readInt();
                dbman.setNextDBId(ois.readInt());
                for (int i = 0; i < numDB; i++) {
                    Logging.logMessage(Logging.LEVEL_DEBUG, this, "loading DB...");
                    final String dbName = (String) ois.readObject();
                    final int dbId = ois.readInt();
                    final int numIndex = ois.readInt();
                    ByteRangeComparator[] comps = new ByteRangeComparator[numIndex];
                    for (int idx = 0; idx < numIndex; idx++) {
                        final String className = (String) ois.readObject();
                        ByteRangeComparator comp = dbman.getComparatorInstances().get(className);
                        if (comp == null) {
                            Class<?> clazz = Class.forName(className);
                            comp = (ByteRangeComparator) clazz.newInstance();
                            dbman.getComparatorInstances().put(className, comp);
                        }
                       
                        assert (comp != null);
                        comps[idx] = comp;
                    }
                   
                    ids.add(dbId);
                   
                    DatabaseInternal db;
                    try {
                        // reset existing DBs
                        db = dbman.getDatabase(dbId);
                        db.setLSMDB(new LSMDatabase(dbName, dbId, dbs.getConfig().getBaseDir()
                                + dbName + File.separatorChar, numIndex, true, comps,
                                dbs.getConfig().getCompression(),
                                dbs.getConfig().getMaxNumRecordsPerBlock(),
                                dbs.getConfig().getMaxBlockFileSize(),
                                dbs.getConfig().getDisableMMap(),
                                dbs.getConfig().getMMapLimit()));
                    } catch (BabuDBException e) {
                        db = new DatabaseImpl(dbs, new LSMDatabase(dbName, dbId,
                                dbs.getConfig().getBaseDir() + dbName + File.separatorChar,
                                numIndex, true, comps, dbs.getConfig().getCompression(),
                                dbs.getConfig().getMaxNumRecordsPerBlock(),
                                dbs.getConfig().getMaxBlockFileSize(),
                                dbs.getConfig().getDisableMMap(),
                                dbs.getConfig().getMMapLimit()));
                       
                        dbman.putDatabase(db);
                    }
                   
                    Logging.logMessage(Logging.LEVEL_INFO, this, "loaded DB %s" + " successfully. [LSN %s]",
                        dbName, db.getLSMDB().getOndiskLSN());
                }
            }
           
            // delete remaining outdated DBs
            Set<Integer> outdatedIds = dbman.getAllDatabaseIds();
            outdatedIds.removeAll(ids);
            if (outdatedIds.size() > 0) {
                for (int id : outdatedIds) {
                    dbman.removeDatabaseById(id);
                }
            }
        } catch (InstantiationException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot instantiate comparator", ex);
        } catch (IllegalAccessException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot instantiate comparator", ex);
        } catch (IOException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "cannot load database config, check path and access rights", ex);
        } catch (ClassNotFoundException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "cannot load database config, config file might be corrupted", ex);
        } catch (ClassCastException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "cannot load database config, config file might be corrupted", ex);
        } finally {
            if (ois != null)
                try {
                    ois.close();
View Full Code Here

                    }
                }
            }
           
        } catch (InstantiationException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot instantiate comparator", ex);
        } catch (IllegalAccessException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR, "cannot instantiate comparator", ex);
        } catch (IOException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "cannot load database config, check path and access rights", ex);
        } catch (ClassNotFoundException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "cannot load database config, config file might be corrupted", ex);
        } catch (ClassCastException ex) {
            throw new BabuDBException(ErrorCode.IO_ERROR,
                "cannot load database config, config file might be corrupted", ex);
        } finally {
            if (ois != null)
                try {
                    ois.close();
View Full Code Here

                    dbFile.delete();
                    tempFile.renameTo(dbFile);
                }
               
            } catch (IOException ex) {
                throw new BabuDBException(ErrorCode.IO_ERROR, "unable to save database configuration", ex);
            }
           
        }
    }
View Full Code Here

       
        try {
            for (int index = 0; index < lsmDB.getIndexCount(); index++)
                lsmDB.getIndex(index).destroy();
        } catch (IOException exc) {
            throw new BabuDBException(ErrorCode.IO_ERROR, exc.getMessage(), exc);
        }
    }
View Full Code Here

            BabuDBRequestResultImpl<Object> result =
                new BabuDBRequestResultImpl<Object>(context, dbs.getResponseManager());
            try {
                w.addRequest(new LSMDBRequest<Object>(lsmDB, result, ins));
            } catch (InterruptedException ex) {
                result.failed(new BabuDBException(ErrorCode.INTERRUPTED,
                        "operation was interrupted", ex));
            }
           
            return result;
        } else {
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.api.exception.BabuDBException

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.