0

5秒ごとに、ノードがサーバーにpingを実行します。pingが成功すると、ノードのタイムスタンプがサーバーデータベースに更新されます.3分ごとに、サーバーは3分より古いタイムスタンプがあるかどうかを確認します。見つかった場合は、データベースからノードを削除します。

今問題。このクエリを実装できません。たとえば、私はそれを次のようなかなり単純な方法で望んでいます:

// Get the server time-stamp in milliseconds

select LastPingedAt from JustPinged where LastPingedAt > 3 Minutes"

// If it finds any,delete each of them from the database.

The logic :
Let the server's time stamp at the point of checking be 'serverStamp'
Let the node's time stamp (time in milliseconds when it last pinged) in the 
database's table be 'nodeStamp'.

If ( serverStamp - nodeStamp > 3 minutes)
// Delete those nodes
If( severStamp - nodeStamp < 3 minutes)
// retain those nodes

さらに実装するクエリを設計できません。

いつでも、JustPingedテーブルは次のようになります。

--------------------------|----------------------
NodesThatJustPinged       |          LastPingedAt
--------------------------|-----------------------
 xxx.xxx.xxx.xxx          |          1355406367402
--------------------------|-----------------------
 yyy.yyy.yyy.yyy          |          1355406421277
--------------------------|-----------------------

時間はミリ秒単位new GregorianCalendar().getTimeInMillis()です。

4

2 に答える 2

3

すべてのレコードを取得して、プログラムで処理する必要はありません。これは、単一のSQLステートメントで実行できます。実行する必要があるのは、次のようなステートメントだけです。

delete from JustPinged where CurrentTime - LastPingedAt > 180000;

したがって、Javaで文字列を作成し、現在の時刻の値を補間して実行する必要があります。

String query = "delete from JustPinged where " +
     [your current time variable here] + " - LastPingedAt > 180000;";

your_statement_object.executeQuery(query);
于 2012-12-13T14:04:03.987 に答える
1

サーバーは、現在のタイムスタンプ(「現在」)を認識しています。したがって、クエリは「LastPingedAt」値がより小さい(現在は-3 * 60 * 1000)すべての行を選択する必要があります。

何かのようなもの

diff := now-180000
select LastPingedAt from JustPinged where LastPingedAt < diff

(擬似コード)

于 2012-12-13T14:04:38.200 に答える