Package com.flaptor.hounder

Examples of com.flaptor.hounder.Index


            String s = "Destination directory exists. The main index should be in an uncorrupted state, so you may try to recover it.";
            logger.error(s);
            throw new IllegalStateException(s);
        } else {
            // Make a copy
            Index newIndexCopy = index.copyIndex(newCopyDir);
            // Set the hostname on the descriptor
            newIndexCopy.getIndexDescriptor().setRsyncAccessString(rsyncAccessString);
            // Close the copy
            newIndexCopy.close();

            // reset the variable that counts inited threads.
            synchronized(updaters) {
                inited = 0;
            }
View Full Code Here


        if (!knownClusters.contains(desc.getClusterName())) {
            return false;
        }

        // If there was an old copy of that index, delete it
        Index oldFromSameCluster = indexes.get(desc.getClusterName());
        if (null != oldFromSameCluster) {
            logger.debug("erasing old index for cluster \"" + desc.getClusterName() + "\".");
            oldFromSameCluster.eraseFromDisk();
        }


        // add it to current indexes
        indexes.put(desc.getClusterName(),index);

        // if we have a copy of each of this clusters, we can
        // create a multi index.
        if (indexes.size() == knownClusters.size()) {
            Index[] toMerge = new Index[knownClusters.size()];
            int i = 0;
            for (String cluster: knownClusters) {
                toMerge[i] = indexes.get(cluster);
                i++;
            }
           
            // Merge them
            File newIndexDirectory = new File(baseDir,"index-"+System.currentTimeMillis());
            newIndexDirectory.mkdirs();
            Index newIndex = MultiIndex.compose(newIndexDirectory,toMerge);

            // delete old reference, and push new index.
            if (null != currentIndex) {
              currentIndex.eraseFromDisk();
            }
View Full Code Here

            throw new IllegalStateException("Server not running.");
        }
        logger.debug("setNewIndex: " + descriptor.toString() + " - " + descriptor.getRemotePath());
        try {
            String location = descriptor.getRemotePath();
            Index currentIndex = library.getCurrentIndex();
            File workingDir = new File(this.indexDir);

            if (location.endsWith("/")) location = location.substring(0,location.length() - 1);

            String newIndexName = location.substring(location.lastIndexOf("/"));

            // Make index copy, in case there is a current index.
            // otherwise, just create the directory
            if (null != currentIndex) {
                Index newIndex = currentIndex.copyIndex(new File(workingDir,newIndexName));
                newIndex.close();
            } else {
                new File(workingDir,newIndexName).mkdirs();
            }

            int exitValue;
            // So, we can now copy the index via rsync
            logger.info("executing rsync");
            exitValue = CommandUtil.execute("rsync -r -v -t -W --delete " + location + " " + workingDir.getCanonicalPath(), null, logger).first();
            logger.info("rsync finished with exit value = " + exitValue);

            if ( 0 != exitValue) {
                // already logged in Execute
                // TODO check what we want to do .. disk is probably full ..
                String msg="Could not make rsync. The disk might be full or may be we are " +
                    "having ssh permission problems. Make sure no SSH_* variables are" +
                    "defined in the environment. Here is the environment: " + System.getenv() ;
                throw new RuntimeException(msg);
            }

            // now, verify that the index did not shrink more than 10%
            File newIndexDir = new File(workingDir,newIndexName);
            if ((null != currentIndex) && (float)(currentIndex.length() * (0.1)) > (float)FileUtil.sizeOf(newIndexDir)) {
                String warning = "Trying to copy an index that shrinked more ";
                warning += "than 10%. It will not be erased nor used by the ";
                warning += "Searcher, and should be checked by a person. It is ";
                warning += " located at " + newIndexDir.getAbsolutePath();
                logger.warn(warning);
                return false;
            }

            // So, size constraints are fine .. Lets try check the index.
            // Read it
            Index index ;
            try {
                index = new Index(newIndexDir);
            } catch (Exception e) {
                logger.error(e,e);
                // Clean corrupted index
                logger.info("deleting directory: " + newIndexDir.getAbsolutePath());
                FileUtil.deleteDir(newIndexDir);
View Full Code Here

            openWriter();
        } else {
            logger.info("constructor: Using latest copy as index.");
            String indexPath = indexDirectory.getAbsolutePath();
            com.flaptor.util.FileUtil.deleteDir(indexPath);
            Index latestCopyIndex = new Index(new File(latestCopy));
            workIndex = latestCopyIndex.copyIndex(indexDirectory);
            IndexDescriptor foundIndexDescriptor = workIndex.getIndexDescriptor();
            if (!indexDescriptor.equals(foundIndexDescriptor)) {
                String s = "This indexer is supposed to serve: " + indexDescriptor.toString() + ", but the index" +
                    " found is: " + foundIndexDescriptor.toString();
                logger.fatal(s);
View Full Code Here

                    System.out.println(e);
                }
            }
            // Write index descriptors
            for (int i = 0; i < numIndexes; i++) {
                Index idx = new Index(new File(indexNames[i]));
                IndexDescriptor idxDescriptor = new IndexDescriptor(numIndexes,i,"defaultCluster");
                idx.setIndexDescriptor(idxDescriptor);
                idx.setIndexProperty("lastOptimization",String.valueOf(System.currentTimeMillis()));
                idx.close();
            }
           
           
            System.out.println("done at " + new Date());
        }
View Full Code Here

        currentIndex = null;
        File indexFile = null;
        for (File file : files) {
            try {
                if (!isLink(file)) {
                    currentIndex = new Index(file);
                    indexFile = file;
                    break; // if successful, this is the latest valid index.
                }
            } catch (Exception e) {
                logger.error("Trying to open the file "+file.getAbsolutePath()+" as an index: "+e,e);
View Full Code Here

        for (int i = 0; i < numServers; i++) {
            setUpIndexer(i);
        }

        Execute.sleep(3000);
        Index index = composer.getCurrentIndex();

        if (index instanceof MultiIndex) {
            assertTrue(true);
        } else {
            assertTrue(false);
View Full Code Here

TOP

Related Classes of com.flaptor.hounder.Index

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.