Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem if you get stuck when performing tasks with MaxCompute Java SDK?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to solve the problem of using MaxCompute Java SDK to carry out tasks. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Scene one

User A

A: "Honey, why is it stuck when you use MaxCompute Java SDK to run your homework?"

Me: "do you have Logview? send it."

A: "No, I use SDK, not Logview."

Scene two

User B

B: "Dear, when you use MaxCompute Java SDK to access Table, why is it stuck for a long time without responding?"

Me: "which line is it stuck in?"

B: "just RestClient retry and get stuck."

Go to the complex and make it simple.

The problem with user An is that there is no logview for instance, which makes it impossible to track the running process of instance.

Usually, after creating an instance, users will call instance.waitForSuccess () to wait for the job to finish. Once the job takes a lot of time, the program will be stuck in this step. If there is a logview, you can check the tracking to see the specific reason why the job is waiting.

The problem with user B is that sdk's Restclient itself has a retry mechanism, which seems to be stuck without any output.

If you output an error each time you retry, you can quickly locate the problem and save time. I have met several public cloud users who have been stuck for a few minutes because of a lack of packets, which has seriously affected their productivity.

Then the problem can be summed up in the following two points:

1 [how to use MaxCompute Java SDK to generate instance Logview]

The answer is simple. MaxCompute Java SDK provides logview interface. For more information, please see SDK Java Doc.

String logview = odps.logview () .generateLogView (instance, 7 * 24)

Two parameters: instance object, logview token timeout (in hours)

Once again, remind users that when using SDK, please record the Logview for each instance and track it quickly if you encounter problems.

Of course, if changing the code is troublesome, there is another trick. You can also get Logview using the wait command in MaxCompute Console.

2 [can you output the error every time you retry? ]

Yes, of course. MaxCompute Java SDK provides an abstract class RetryLogger for more details, see SDK Java Doc.

Public static abstract class RetryLogger {/ * callback function before RestClent retry * * @ param e * error exception * @ param retryCount * retry count * @ param retrySleepTime * next retry time * / public abstract void onRetryLog (Throwable e, long retryCount, long retrySleepTime);}

Users only need to implement one of their own RetryLogger subclasses, and then use odps.getRestClient (). SetRetryLogger (new UserRetryLogger ()); to output the log when initializing the odps object.

A typical implementation is as follows:

/ / init odpsodps.getRestClient () .setRetryLogger (new UserRetryLogger ()); / / your retry loggerpublic class UserRetryLogger extends RetryLogger {@ Override public void onRetryLog (Throwable e, long retryCount, long sleepTime) {if (e! = null & & e instanceof OdpsException) {String requestId = ((OdpsException) e) .getRequestId () If (requestId! = null) {System.err.println ("Warning: ODPS request failed, requestID:%s, retryCount:%d, will retry in% d seconds.", requestId, retryCount, sleepTime); return }} System.err.println ("Warning: ODPS request failed:%s, retryCount:%d, will retry in% d seconds.", e.getMessage (), retryCount, sleepTime);}}

After reading the above, do you have any further understanding of how to solve the problem of using MaxCompute Java SDK to execute a task stuck? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report