how to capture the retention bytes values from zookeeper meta data - apache-kafka

we are trying to capture the retention bytes values from the topic - topic_test
we try the following example , but seems this isnt the right path from zookeeper
zookeeper-shell kafka1:2181,kafka2:2181,kafka3:2181 <<< "ls /brokers/topics/topic_test/partitions/88/state"
Connecting to kafka1:2181,kafka2:2181,kafka3:2181
Welcome to ZooKeeper!
JLine support is disabled
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[]
any idea where are the values of retention bytes per topic that can capture from zookeeper?
I did the following , but not see the retention bytes ( what is wrong here ) , we have kafka confluent version - 0.1
zookeeper-shell confluent1:2181 get /config/topics/test_topic
Connecting to kafka1:2181
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
{"version":1,"config":{}}
cZxid = 0xb30a00000038
ctime = Mon Jun 29 11:42:30 GMT 2020
mZxid = 0xb30a00000038
mtime = Mon Jun 29 11:42:30 GMT 2020
pZxid = 0xb30a00000038
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 25
numChildren = 0

Configurations are stored in Zookeeper under the /config path.
For example, for the topic topic_test:
# Create topic
./bin/kafka-topics.sh --bootstrap-server localhost:9092 --create \
--topic topic_test --partitions 1 --replication-factor 1 --config retention.bytes=12345
# Retrieve configs from Zookeeper
./bin/zookeeper-shell.sh localhost get /config/topics/topic_test
Connecting to localhost
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
{"version":1,"config":{"retention.bytes":"12345"}}
Note in most cases, you should not rely on direct access to Zookeeper but instead use the Kafka API to retrieve these values.
Using:
kafka-topics.sh:
./bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic topic_test
kafka-configs.sh:
./bin/kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type topics --entity-name topic_test
The Admin API using describeConfigs()

Related

Is a broker required to create a topic?

I list the brokers using: /opt/confluent-kafka/v5.5.0/bin/zookeeper-shell localhost:2181 ls /brokers/ids
Which returns:
Connecting to localhost:2181
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[0]
Which shows no brokers running.
I then create a topic using:
[test#bhop logs]$ /opt/confluent-kafka/v5.5.0/bin/kafka-topics --create \
> --zookeeper localhost:2181 \
> --replication-factor 1 \
> --partitions 1 \
> --topic test
Created topic test.
And can see the topic is created:
/opt/confluent-kafka/v5.5.0/bin/kafka-topics --list --zookeeper localhost:2181
returns:
__confluent.support.metrics
test-topic
As there are no brokers running how can a topic be created? Is a running broker not required to create a topic ?
[0] shows there's one broker with id 0. The ids znode would not exist if no brokers were running
You should get /brokers/ids/0 to see the broker data
If it looks correct, things are working as expected
Note: --zookeeper flag is deprecated in latest Kafka CLIs

how to remaine the kafka retentions-bytes and kafka retention-segment even after kafka machine reboot [duplicate]

This question already exists:
kafka + how to set specific retention byets for specific topic as permamnet
Closed 2 years ago.
we set retention bytes value - 104857600 for topic - topic_test
[root#confluent01 ~]# kafka-topics --zookeeper localhost:2181 --alter --topic topic_test --config retention.bytes=104857600
WARNING: Altering topic configuration from this script has been deprecated and may be removed in future releases.
Going forward, please use kafka-configs.sh for this functionality
Updated config for topic "topic_test".
Now we verify the retention bytes from the zookeeper:
[root#confluent01 ~]# zookeeper-shell confluent01:2181 get /config/topics/topic_test
Connecting to confluent1:2181
{"version":1,"config":{"retention.bytes":"104857600"}}
cZxid = 0xb30a00000038
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
ctime = Mon Jun 29 11:42:30 GMT 2020
mZxid = 0xb31100008978
mtime = Wed Jul 22 19:22:20 GMT 2020
pZxid = 0xb30a00000038
cversion = 0
dataVersion = 7
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 54
numChildren = 0
now we performed reboot to the kafka confluent01 machine
after machines started and kafka service start successfully , we checked again the retention-bytes from zookeeper:
but now ( after machine reboot ) we can see that the retention bytes isn't configured in zookeeper
[root#confluent01 ~]#zookeeper-shell confluent01:2181 get /config/topics/topic_test
Connecting to confluent1:2181
WATCHER::
WatchedEvent state:SyncConnected type:None path:null  no retention bytes value
{"version":1,"config":{}}
cZxid = 0xb30a00000038
ctime = Mon Jun 29 11:42:30 GMT 2020
mZxid = 0xb3110000779b
mtime = Wed Jul 22 14:09:19 GMT 2020
pZxid = 0xb30a00000038
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 25
numChildren = 0
the question is - how to remain the retention bytes even after restart of kafka machine ?
NOTE - we not want to use the retention bytes from server.properties
because we set different retention bytes to each topic
Zookeeper and Kafka default to store data in /tmp
If you reboot the machines, /tmp is cleared
Otherwise, if you use confluent start command, this is not permanent data.
If you use Docker/Kubernetes without mounting any volumes, this is also not permanent.
You sould also be using kafka-topics --describe command rather than zookeeper-shell as Zookeeper will be removed completely in upcoming Kafka releases

How to check Kafka server status or details?

Is there a command to show the details of Kafka server or the status of Kafka server? (I am not trying to find out if the kafka server is running.)
I can only find information on topic, partition, producer, and consumer CLI commands.
If you are looking for the Kafka cluster broker status, you can use zookeeper cli to find the details for each broker as given below:
ls /brokers/ids returns the list of active brokers IDs on the cluster.
get /brokers/ids/<id> returns the details of the broker with the given ID.
Example :
kafka_2.12-1.1.1 % ./bin/zookeeper-shell.sh localhost:2181 ls /brokers/ids
Connecting to localhost:2181
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[0]
kafka_2.12-1.1.1 % ./bin/zookeeper-shell.sh localhost:2181 get /brokers/ids/0
Connecting to localhost:2181
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://localhost:9092"],"jmx_port":-1,"host":"localhost","timestamp":"1558428038778","port":9092,"version":4}
cZxid = 0x116
ctime = Tue May 21 08:40:38 UTC 2019
mZxid = 0x116
mtime = Tue May 21 08:40:38 UTC 2019
pZxid = 0x116
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x16ad9830f16000b
dataLength = 188
numChildren = 0
You can put these steps in some shell script to get the details for all brokers.
You can activate JMX metrics by setting environment variable JMX_PORT.
$ export JMX_PORT=9010
$ ./bin/kafka-server-start.sh ./config/server.properties
Then, you can use jconsole or Java Mission Control to display cluster metrics.

Kafka(0.9.0.0) gives ArrayIndexOutOfBoundsException

Steps followed:
cd /opt/kafka_2.11-0.9.0.0
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topic-test
bin/kafka-topics.sh --list --zookeeper localhost:2181
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topic-test
Time of occurance: The moment You write anything in the producer bash this error starts coming up
Already Tried: eleting topics from zookeper bash and removing topic logs in tmp location
[2018-10-25 10:03:17,919] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
[2018-10-25 10:03:18,080] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [topic-test,0] (kafka.server.ReplicaFetcherManager)
[2018-10-25 10:03:18,099] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions [topic-test,0] (kafka.server.ReplicaFetcherManager)
[2018-10-25 10:03:48,864] ERROR Processor got uncaught exception. (kafka.network.Processor)
java.lang.ArrayIndexOutOfBoundsException: 18
at org.apache.kafka.common.protocol.ApiKeys.forId(ApiKeys.java:68)
at org.apache.kafka.common.requests.AbstractRequest.getRequest(AbstractRequest.java:39)
at kafka.network.RequestChannel$Request.<init>(RequestChannel.scala:79)
at kafka.network.Processor$$anonfun$run$11.apply(SocketServer.scala:426)
at kafka.network.Processor$$anonfun$run$11.apply(SocketServer.scala:421)
at scala.collection.Iterator$class.foreach(Iterator.scala:742)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1194)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at kafka.network.Processor.run(SocketServer.scala:421)
at java.lang.Thread.run(Thread.java:748)
It would be very helpful if someone provides a deep insight for trouble shooting other error like this in the future.
I downloaded the latest /kafka_2.11-2.0.0 and followed the steps:
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topic-test
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topic-test
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic-test --from-beginning
Things working fine.
Please note --bootstrap-server localhost:9092 has changed in consumer script

Kafka 0.8.2.2 - Compact mode not work

I am new beginner of kafka, i try to use COMPACT mode in kafka.
I look kafka document, I think setting log.cleaner.enable=true and log.cleanup.policy=compact for COMPACT modem, but it seem not work.
Could you please help me. Thanks.
environment
Ubuntu 14.04.3 LTS
Kafka kafka_2.11-0.8.2.2
kafka config
log.retention.ms=10000
log.retention.check.interval.ms=1000
log.cleaner.enable=true
log.cleaner.delete.retention.ms=1000
log.cleaner.backoff.ms=1000
log.cleaner.min.cleanable.ratio=0.01
log.cleanup.policy=compact
At kafka log, i see 'INFO [kafka-log-cleaner-thread-0], Starting (kafka.log.LogCleaner)’, so i think success to enable COMPACT mode.
I follow QUICK START of kafka document, and input some data to test topic.
root#50d8fe84c573:~/kafka_2.11-0.8.2.2# date
Sun Jan 10 14:23:26 UTC 2016
root#50d8fe84c573:~/kafka_2.11-0.8.2.2# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
[2016-01-10 14:23:38,312] WARN Property topic is not valid (kafka.utils.VerifiableProperties)
22:23:45
22:24:05
22:25:00
root#50d8fe84c573:~/kafka_2.11-0.8.2.2# date
Sun Jan 10 14:25:21 UTC 2016
root#50d8fe84c573:~/kafka_2.11-0.8.2.2# ./bin/kafka-console-consumer.sh --zookeeper localhost --topic test --from-beginning --property print.key=true
null 22:23:45
null 22:24:05
null 22:25:00
root#50d8fe84c573:~/kafka_2.11-0.8.2.2# date
Sun Jan 10 14:30:06 UTC 2016
root#50d8fe84c573:~/kafka_2.11-0.8.2.2# ./bin/kafka-console-consumer.sh --zookeeper localhost --topic test --from-beginning --property print.key=true
null 22:23:45
null 22:24:05
null 22:25:00
I expect only keep on same key, so 22:23:45 and 22:24:05 message will be removed.
Thanks for morganw suggest. I have been push message of has key.
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# ./bin/kafka-topics.sh --zookeeper localhost --topic test --delete
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# date
Wed Jan 13 01:21:59 UTC 2016
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# bpython3
from kafka import (
KafkaClient, KeyedProducer,
Murmur2Partitioner, RoundRobinPartitioner)
kafka = KafkaClient('localhost:9092')
producer = KeyedProducer(kafka)
>>> producer.send_messages(b'test', b'key', b'09:22:08')
[ProduceResponse(topic=b'test', partition=0, error=0, offset=0)]
>>> producer.send_messages(b'test', b'key', b'09:22:28')
[ProduceResponse(topic=b'test', partition=0, error=0, offset=1)]
>>> producer.send_messages(b'test', b'key', b'09:23:00')
[ProduceResponse(topic=b'test', partition=0, error=0, offset=2)]
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# date
Wed Jan 13 01:23:05 UTC 2016
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# ./bin/kafka-console-consumer.sh --zookeeper localhost --topic test --from-beginning --property print.key=true
key 09:22:08
key 09:22:28
key 09:23:00
^CConsumed 3 messages
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# date
Wed Jan 13 01:27:18 UTC 2016
root#9d8bdae48429:~/kafka_2.11-0.8.2.2# ./bin/kafka-console-consumer.sh --zookeeper localhost --topic test --from-beginning --property print.key=true
key 09:22:08
key 09:22:28
key 09:23:00
But in result, the test topic still keep ALL message.
I don’t know i miss somehow.
Could you please help me? Thanks. :-)