Skip to main content



Spark Streaming Kafka Errors

 

We observed couple of errors / info messages while running Spark Streaming Applications, which might come  handy for debugging in future. Refer below - 

1) We noticed that Spark streaming Job was running but consuming nothing. We could see following messages being iteratively printed in logs - 


22/11/18 08:13:53 INFO AbstractCoordinator: [Consumer clientId=consumer-1, groupId=difnrt-uat-001] Group coordinator mymachine.com:9093 (id: 601150796 rack: null) is unavailable or invalid, will attempt rediscovery

22/11/18 08:13:53 INFO AbstractCoordinator: [Consumer clientId=consumer-1, groupId=difnrt-uat-001] Discovered group coordinator mymachine.com:9093 (id: 601150796 rack: null)

22/11/18 08:13:53 INFO AbstractCoordinator: [Consumer clientId=consumer-1, groupId=difnrt-uat-001] (Re-)joining group


Possible Causes / Fixes - 

  • May be due to Kafka Coordinator service. Try restarting Kafka it may fix the issue. 
  • In our case, we couldn't get help from Admin Team. So, we changed "group.id" which resolved issue for us.

2) Noticed Spark Streaming Job giving below error while producing messages to Kafka - 


org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.


Possible Causes / Fixes - 
  • It means that Client thread is being timed out before data is being written to Bootstrap server. There can be more reasons which can actually be derived from Kafka Server logs. Client logs don't provide much information.
  • In our case, it was firewall issue with some nodes in cluster which could not connect to Kafka Bootstrap servers. So, it used to work but when tasks used to execute on machine which doesn't have firewall open - that's when application used to fail. To identify it - 
    • we did SSH to those nodes 
    • executed below command's to know if connection is possible -
                    telnet <machine> <port> 
                    or,
                    nc -zv <machine> <port>

  • Opening firewall ports helped solve this intermittent problem. 

3) Spark Streaming with Kafka failing with below error -

java.lang.IllegalArgumentException: requirement failed: numRecords must not be negative
at scala.Predef$.require(Predef.scala:224)
at org.apache.spark.streaming.scheduler.StreamInputInfo.<init>(InputInfoTracker.scala:38)
at org.apache.spark.streaming.kafka010.DirectKafkaInputDStream.compute(DirectKafkaInputDStream.scala:231)

Possible Causes / Fixes - 
  • The reason for this error is that we are trying to fetch an offset which is greater then the current latest offset known by the broker. There can be multiple reasons for this behavior - 
  • On Kafka Side - 
    • set clean.leader.election.enable to false, such that there are no in-sync replicas.
    • Restart Kafka after there are no in-sync replicas.
    • Now, if offset was maintained by Kafka it should get corrected and re-running Spark Streaming application should work.
  • In my case - it was due to coding error - 
    • We were maintaining offset manually in an HBase Table. 
    • Due to a coding error - we inserted wrong value in HBase Table. 
    • Next time when our Job ran it selected large offset from HBase Table which did not exists for the topic resulting in this error.
    • We corrected our code and offset entries which resolved the issue.

Comments

Popular posts

Unix Server ( Edge Node ) hangs when there are many jobs running on hadoop cluster started from Unix Edge Node.

  When a unix server or an edge node is running lots of jobs (like Spark, Hadoop, or custom batch processes), crashes happen. For example. For example a process might hit a segementation fault, memory issue or ay other runtime issue. By default, if ulimit -c is not 0, the OS will create core dump. Core dump are written to disk and can be very large, sometimes hundreds of MBs or even GBs per process. What we realized was that when multiple processes crash at the same time, the system suddenly tries to write core files to disk. This was leading to DisK I/O spikes. Thus, node was becoming unresponsive. This was also leading CPU spike because OS was handling crash logging. Setting "ulimit -c 0" disables core dumps. This way we lose ability to debug crashes via core dump But, kept production edge nodes stable. On most Linux systems, by default, "core dumps" are written in current working directory of the process that crashes. Linux allows you to change core dump file nam...




VPN testing checklist

 To test: Is VPN active? Is it leaking? Does it look residential? Does it alter network fingerprints? Public IP Test (Basic Detection) - curl ipinfo.io DNS Leak Test - nslookup google.com MTU Test (Encapsulation Detection) - ping 8.8.8.8 -f -l 1472 TCP MSS Inspection - Use Wireshark and Look for SYN packets. Traceroute Path Test - tracert 8.8.8.8 WebRTC Leak Test - browserleaks.com/webrtc IPv6 Leak Test - test-ipv6.com Latency / Jitter Test - ping -n 50 8.8.8.8. VPN usually causes: More Jitters and Latency. Reverse DNS (PTR Record) - nslookup <your-public-ip> IP Reputation Check - Like most IP's from VPN Providers like Express VPN, etc. are blacklisted and all. Look for: Proxy/VPN classification, Hosting provider tagging




Spark-JDBC connection with Oracle Fails - java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name

  While connecting Spark with Oracle JDBC, one may observe exception like below -  spark.read.format("jdbc"). option("url", "jdbc:oracle:thin:@//oraclehost:1521/servicename"). option("dbtable", "mytable"). option("user", "myuser").option("driver", "oracle.jdbc.driver.OracleDriver") option("password", "mypassword"). load().write.parquet("/data/out") java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208) ...




Agentic AI Development- Optimization- Bedrock Claude

Most of the models which you wish to invoke via AWS Bedrock, GPT, Google, etc, charges per token ( words/ characters ) For example -  A model like Claude is not a computer program that executes instructions. It is a statistical pattern matcher trained on text. It has no CPU, no memory, no ability to run code. It only predicts the next most likely token based on patterns it saw during training. But, some AI platforms give the model a sandboxed Python environment to actually execute code. Bedrock does have a Code Interpreter tool in Bedrock Agents — but that's a completely different setup- the overhead of setting it up just to decompress JSON makes zero sense when simply sending clean JSON is trivially easy. Easy Way To Estimate Your Cost- Step 1 — Measure your actual prompt size: Take your evidence JSON + instructions Paste into: https://platform.openai.com/tokenizer (OpenAI's tokenizer is close enough for estimation) It will tell you exact token count Step2 - Cost calculation C...




Spring MongoDB Rest API not returning response in 90 seconds which is leading to client timeout

  We have Spring Boot  Rest API deployed in Kubernetes cluster which integrates with MongoDB to fetch the data.  MongoDB is fed with data by a real time Spark & NiFi job.  Our clients complained that for a request what they send they don't have response within 90 seconds. Consider it like an OMS ( Order ManagEment System).  On further analysis, we found that Spark & NiFi processing is happenning within 10 seconds after consuming response data from Kafka. Thus, initally out thought was that it due to delay from upstream to produce data in to Kafka.  Thankfully, our data had create / request  timestamp, and when response was received, and when response was inserted into MongoDB. Subtracting response insert time from request time seemed to be well within 90 seconds. But, still client did timeout on not seeing a response within 90 seconds. This led to confusion on our side.  But, then we realized it was due to Read Preference . We updated this...