public synchronized String deploy(String saZipURL) throws Exception { File dir = null; try { // Check that the url is valid URI uri = new URI(saZipURL); // Create a temporary dir dir = Directories.getNewTempDir(this.container.getWorkingDir()); IOUtils.createDirs(dir); File archive = new File(dir, "jbi.zip"); // Download file IOUtils.copy(uri.toURL(), archive); // Install from the downloaded file // Unzip file to temp dir File unzip = new File(dir, "unzip"); IOUtils.unzip(archive, unzip); // Load jbi descriptor File jbiFile = new File(unzip, JBI_DESCRIPTOR); Jbi jbi = JbiDocument.Factory.parse(jbiFile).getJbi(); // Check version number if (jbi.getVersion().doubleValue() != 1.0) { throw new JBIException("version attribute should be '1.0'"); } // Check that it is a component if (!jbi.isSetServiceAssembly()) { throw new JBIException("service-assembly should be set"); } // Move unzipped files to install dir String name = jbi.getServiceAssembly().getIdentification().getName(); // Check that it is not already installed if (this.registry.getAssembly(name) != null) { throw new JBIException("Service assembly is already installed"); } File installDir = Directories.getAssemblyInstallDir(this.container.getWorkingDir(), name); if (!unzip.renameTo(installDir)) { throw new IOException("Could not rename directory: " + unzip); } // Create assembly Assembly assembly = this.registry.addAssembly(name); assembly.setDescriptor(jbi); assembly.setInstallRoot(installDir.getAbsolutePath()); String result = assembly.deploy(); return result; } catch (Exception e) { LOGGER.error("Could not install shared library", e); throw new RuntimeException("Could not install shared library", e); } finally { IOUtils.deleteFile(dir); } }
@Test public void testRangeTombstones() throws IOException, ExecutionException, InterruptedException { Keyspace keyspace = Keyspace.open(KEYSPACE1); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard2"); cfs.clearUnsafe(); // disable compaction while flushing cfs.disableAutoCompaction(); final CFMetaData cfmeta = cfs.metadata; Directories dir = cfs.directories; ArrayList<DecoratedKey> keys = new ArrayList<DecoratedKey>(); for (int i = 0; i < 4; i++) { keys.add(Util.dk("" + i)); } ArrayBackedSortedColumns cf = ArrayBackedSortedColumns.factory.create(cfmeta); cf.addColumn(Util.column("01", "a", 1)); // this must not resurrect cf.addColumn(Util.column("a", "a", 3)); cf.deletionInfo() .add( new RangeTombstone( Util.cellname("0"), Util.cellname("b"), 2, (int) (System.currentTimeMillis() / 1000)), cfmeta.comparator); SSTableWriter writer = new SSTableWriter( cfs.getTempSSTablePath(dir.getDirectoryForNewSSTables()), 0, 0, cfs.metadata, StorageService.getPartitioner(), new MetadataCollector(cfs.metadata.comparator)); writer.append(Util.dk("0"), cf); writer.append(Util.dk("1"), cf); writer.append(Util.dk("3"), cf); cfs.addSSTable(writer.closeAndOpenReader()); writer = new SSTableWriter( cfs.getTempSSTablePath(dir.getDirectoryForNewSSTables()), 0, 0, cfs.metadata, StorageService.getPartitioner(), new MetadataCollector(cfs.metadata.comparator)); writer.append(Util.dk("0"), cf); writer.append(Util.dk("1"), cf); writer.append(Util.dk("2"), cf); writer.append(Util.dk("3"), cf); cfs.addSSTable(writer.closeAndOpenReader()); Collection<SSTableReader> toCompact = cfs.getSSTables(); assert toCompact.size() == 2; // Force compaction on first sstables. Since each row is in only one sstable, we will be using // EchoedRow. Util.compact(cfs, toCompact); assertEquals(1, cfs.getSSTables().size()); // Now assert we do have the 4 keys assertEquals(4, Util.getRangeSlice(cfs).size()); ArrayList<DecoratedKey> k = new ArrayList<DecoratedKey>(); for (Row r : Util.getRangeSlice(cfs)) { k.add(r.key); assertEquals(ByteBufferUtil.bytes("a"), r.cf.getColumn(Util.cellname("a")).value()); assertNull(r.cf.getColumn(Util.cellname("01"))); assertEquals(3, r.cf.getColumn(Util.cellname("a")).timestamp()); } for (SSTableReader sstable : cfs.getSSTables()) { StatsMetadata stats = sstable.getSSTableMetadata(); assertEquals(ByteBufferUtil.bytes("0"), stats.minColumnNames.get(0)); assertEquals(ByteBufferUtil.bytes("b"), stats.maxColumnNames.get(0)); } assertEquals(keys, k); }