Search in sources :

Example 31 with PhysicalPartition

use of com.linkedin.databus.core.data_model.PhysicalPartition in project databus by linkedin.

the class DbusEventBufferMult method addNewBuffer.

//CM API
/** add new buffer
   * also checks if any buffers should be removed
   * @throws InvalidConfigException */
public synchronized DbusEventBuffer addNewBuffer(PhysicalSourceStaticConfig pConfig, DbusEventBuffer.StaticConfig config) throws InvalidConfigException {
    long startTimeTs = System.nanoTime();
    if (config == null)
        throw new InvalidConfigException("config cannot be null for addNewBuffer");
    // see if a buffer for this mapping exists
    PhysicalPartition pPartition = pConfig.getPhysicalPartition();
    PhysicalPartitionKey pKey = new PhysicalPartitionKey(pPartition);
    //record pSource association to the buffer
    PhysicalSource pSource = pConfig.getPhysicalSource();
    Set<PhysicalSource> set = _partKey2PhysiscalSources.get(pKey);
    if (set == null) {
        set = new HashSet<PhysicalSource>();
        _partKey2PhysiscalSources.put(pKey, set);
    }
    set.add(pSource);
    DbusEventBuffer buf = _bufsMap.get(pKey);
    if (buf != null) {
        LOG.info("Adding new buffer. Buffer " + buf.hashCode() + " already exists for: " + pConfig);
    } else {
        if (pConfig.isDbusEventBufferSet()) {
            buf = new DbusEventBuffer(pConfig.getDbusEventBuffer(), pPartition, _eventFactory);
            LOG.info("Using- source specific event buffer config, the event buffer size allocated is: " + buf.getAllocatedSize());
        } else {
            buf = new DbusEventBuffer(config, pPartition, _eventFactory);
            LOG.info("Using- global event buffer config, the buffer size allocated is: " + buf.getAllocatedSize());
        }
        addBuffer(pConfig, buf);
    }
    buf.increaseRefCounter();
    // check if some buffers need to be removed
    deallocateRemovedBuffers(false);
    long endTimeTs = System.nanoTime();
    if (PERF_LOG.isDebugEnabled()) {
        PERF_LOG.debug("addNewBuffer took:" + (endTimeTs - startTimeTs) / _nanoSecsInMSec + "ms");
    }
    return buf;
}
Also used : PhysicalSource(com.linkedin.databus.core.data_model.PhysicalSource) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 32 with PhysicalPartition

use of com.linkedin.databus.core.data_model.PhysicalPartition in project databus by linkedin.

the class DbusEventBufferMult method constructFilters.

/**
   * Processes all {@link DatabusSubscription} and generates a filter to match events for any of
   * those subscriptions.
   */
public DbusFilter constructFilters(Collection<DatabusSubscription> subs) throws DatabusException {
    HashMap<PhysicalPartition, PhysicalPartitionDbusFilter> filterMap = null;
    for (DatabusSubscription sub : subs) {
        PhysicalPartition ppart = sub.getPhysicalPartition();
        if (sub.getLogicalSource().isWildcard()) {
            if (!ppart.isWildcard()) {
                if (null == filterMap)
                    filterMap = new HashMap<PhysicalPartition, PhysicalPartitionDbusFilter>(10);
                filterMap.put(ppart, new PhysicalPartitionDbusFilter(ppart, null));
            } else {
                LOG.warn("ignoring subscription with both physical partition and logical source wildcards");
            }
        } else {
            PhysicalPartitionDbusFilter ppartFilter = null != filterMap ? filterMap.get(ppart) : null;
            LogicalSourceAndPartitionDbusFilter logFilter = null;
            if (null == ppartFilter) {
                logFilter = new LogicalSourceAndPartitionDbusFilter();
                ppartFilter = new PhysicalPartitionDbusFilter(ppart, logFilter);
                if (null == filterMap)
                    filterMap = new HashMap<PhysicalPartition, PhysicalPartitionDbusFilter>(10);
                filterMap.put(ppart, ppartFilter);
            } else {
                logFilter = (LogicalSourceAndPartitionDbusFilter) ppartFilter.getNestedFilter();
            }
            if (null != logFilter)
                logFilter.addSourceCondition(sub.getLogicalPartition());
            else
                LOG.error("unexpected null filter for logical source");
        }
    }
    if (0 == filterMap.size())
        return AllowAllDbusFilter.THE_INSTANCE;
    else if (1 == filterMap.size()) {
        DbusFilter result = filterMap.entrySet().iterator().next().getValue();
        return result;
    } else {
        ConjunctionDbusFilter result = new ConjunctionDbusFilter();
        for (Map.Entry<PhysicalPartition, PhysicalPartitionDbusFilter> filterEntry : filterMap.entrySet()) {
            result.addFilter(filterEntry.getValue());
        }
        return result;
    }
}
Also used : PhysicalPartitionDbusFilter(com.linkedin.databus2.core.filter.PhysicalPartitionDbusFilter) HashMap(java.util.HashMap) ConjunctionDbusFilter(com.linkedin.databus2.core.filter.ConjunctionDbusFilter) LogicalSourceAndPartitionDbusFilter(com.linkedin.databus2.core.filter.LogicalSourceAndPartitionDbusFilter) DatabusSubscription(com.linkedin.databus.core.data_model.DatabusSubscription) ConjunctionDbusFilter(com.linkedin.databus2.core.filter.ConjunctionDbusFilter) AllowAllDbusFilter(com.linkedin.databus2.core.filter.AllowAllDbusFilter) LogicalSourceAndPartitionDbusFilter(com.linkedin.databus2.core.filter.LogicalSourceAndPartitionDbusFilter) PhysicalPartitionDbusFilter(com.linkedin.databus2.core.filter.PhysicalPartitionDbusFilter) DbusFilter(com.linkedin.databus2.core.filter.DbusFilter) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 33 with PhysicalPartition

use of com.linkedin.databus.core.data_model.PhysicalPartition in project databus by linkedin.

the class CheckpointMult method serialize.

/**
   * serialize CheckpointMult into the stream
   * @param outStream
   */
void serialize(OutputStream outStream) throws JsonGenerationException, JsonMappingException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // first convert checkpointmult into a map
    Map<String, String> map = new HashMap<String, String>();
    boolean debugEnabled = LOG.isDebugEnabled();
    for (Entry<PhysicalPartition, Checkpoint> e : _pPart2Checkpoint.entrySet()) {
        baos.reset();
        Checkpoint cp = e.getValue();
        cp.serialize(baos);
        String pPartJson = e.getKey().toJsonString();
        String cpStr = StringUtils.bytesToString(baos.toByteArray());
        map.put(pPartJson, cpStr);
        if (debugEnabled)
            LOG.debug("phSourId=" + e.getKey() + ";cp =" + cpStr);
    }
    _mapper.writeValue(outStream, map);
}
Also used : HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 34 with PhysicalPartition

use of com.linkedin.databus.core.data_model.PhysicalPartition in project databus by linkedin.

the class TestDatabusRequest method testToString.

@Test
public void testToString() throws Exception {
    DatabusRequest req = makeRequest();
    // Coverage of toString().
    String jsonStr = req.toString();
    Map<String, String> jsonMap = _objectMapper.readValue(jsonStr.getBytes(Charset.defaultCharset()), new TypeReference<Map<String, String>>() {
    });
    Assert.assertEquals(reqName, jsonMap.get("name"));
    Assert.assertEquals(method.toString(), jsonMap.get("method"));
    Assert.assertEquals(propval1, jsonMap.get(prop1));
    Assert.assertEquals(propval2, jsonMap.get(prop2));
    Assert.assertEquals(4, jsonMap.size());
    // Coverage for null processor.
    Assert.assertEquals(req, req.call());
    // Coverqage for setCursorPartition
    PhysicalPartition pp = new PhysicalPartition(15, "SomePartition");
    req.setCursorPartition(pp);
    Assert.assertEquals(pp, req.getCursorPartition());
    Assert.assertFalse(req.cancel(true));
    Assert.assertFalse(req.cancel(false));
    Assert.assertEquals(req, req.get());
    Assert.assertEquals(req, req.get(89L, TimeUnit.HOURS));
    Assert.assertFalse(req.isCancelled());
    InetSocketAddress remoteAddress = (InetSocketAddress) req.getRemoteAddress();
    Assert.assertEquals(port, remoteAddress.getPort());
    Assert.assertEquals(InetAddress.getByAddress(ipAddr), remoteAddress.getAddress());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) Test(org.testng.annotations.Test)

Example 35 with PhysicalPartition

use of com.linkedin.databus.core.data_model.PhysicalPartition in project databus by linkedin.

the class DatabusRelayMain method pause.

@Override
public void pause() {
    for (Entry<PhysicalPartition, EventProducer> entry : _producers.entrySet()) {
        EventProducer producer = entry.getValue();
        if (null != producer) {
            if (producer.isRunning()) {
                producer.pause();
                LOG.info("EventProducer :" + producer.getName() + "  pause sent");
            } else if (producer.isPaused()) {
                LOG.info("EventProducer :" + producer.getName() + "  already paused");
            }
        }
    }
}
Also used : OracleEventProducer(com.linkedin.databus2.producers.db.OracleEventProducer) RelayEventProducer(com.linkedin.databus2.producers.RelayEventProducer) EventProducer(com.linkedin.databus2.producers.EventProducer) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Aggregations

PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)47 Test (org.testng.annotations.Test)22 BeforeTest (org.testng.annotations.BeforeTest)13 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)8 PhysicalPartitionKey (com.linkedin.databus.core.DbusEventBufferMult.PhysicalPartitionKey)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)6 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)6 AllowAllDbusFilter (com.linkedin.databus2.core.filter.AllowAllDbusFilter)6 EventProducer (com.linkedin.databus2.producers.EventProducer)6 RelayEventProducer (com.linkedin.databus2.producers.RelayEventProducer)6 OracleEventProducer (com.linkedin.databus2.producers.db.OracleEventProducer)6 HashMap (java.util.HashMap)6 DbusEventsTotalStats (com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 DbusEventBufferMult (com.linkedin.databus.core.DbusEventBufferMult)4 AggregatedDbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsStatisticsCollector)4 ConjunctionDbusFilter (com.linkedin.databus2.core.filter.ConjunctionDbusFilter)4 DbusFilter (com.linkedin.databus2.core.filter.DbusFilter)4