Archive for the ‘database’ Category

 

redis-ranking sorted set の sort order desc が機能しない。。。

3月 19th, 2013

( redis 2.4ではダメでしたが、2.6は問題なく動きました。) sorted set で スコア昇順に並んでいるので by nosort desc で取得出来ると思っていたらなぜかできない。 SORT sortedsetlist BY nosort SORT sortedsetlist BY nosort DESC どちらも同じ・・・ ZREVRANGE sortedsetlist 0 -1 WITHSCORES とかはちゃんとスコア降順になります。 by nosort DESCは絶対行けると思ってたけどダメだった。。。 zcount を調べてlimitで後ろから順に取るという裏技もあるけど・・・ ZCOUNT sortedsetlist -inf +inf scoreをマイナスで入れるというパターンもあるけど・・・ それが一番分かりやすいかな・・・ と思ったけど2.4じゃなくて 2.6 だと行けるっぽいので 2.6 にしてみました。 scoreでsortできました!ということで sorted setでsort *** get *** を使いたい場合は、2.6が良いみたいです。 predisの書き方。predisのsortの書き方があまりなかったので残しておきます。 predisのところだけ $this->redis = new […]

Read full article | コメントは受け付けていません。

fluentd pluginを書いてみる。 redis-ranking

3月 18th, 2013

rubyあまり書いたこと無いけど、ちょっと書けば動きそうなので http://docs.fluentd.org/articles/plugin-development#writing-buffered-output-plugins http://documents.mazgi.com/fluentd/doc/devel.html#buffered-output-plugins http://fluentd.org/plugin/ を参考に。 event_id rank_key を設定するくらい。 * rubyは、あまり何も見たこと無いのですが はめ込んだだけなので、普通だとは思いますが、枠がしっかりしているので簡単になんでも作れそうです。 * はめ込んで1回で問題なく動いたので、コードを書いたのは5分くらいでしょうか、サンプル色々見て1時間 + ライブラリの設定がわからず1時間と言う感じです。 out_event_rank.rb class Fluent::EventRankOutput < Fluent::BufferedOutput    Fluent::Plugin.register_output(‘event_rank’, self)    config_param :host, :string    config_param :port, :integer, :default => 30110    config_param :event_id, :string    config_param :rank_key, :string    def initialize      super      require ‘redis’    end   […]

Read full article | コメントは受け付けていません。

partition table range

2月 23rd, 2013

ERROR 1503 (HY000) at line 35: A PRIMARY KEY must include all columns in the table’s partitioning function プライマリーキーにpartitionキーが入っている必要がある。 CREATE TABLE IF NOT EXISTS `payment` ( `user_id` varchar(32) NOT NULL, `item_id` int NOT NULL, /* 略 */ `created_at` TIMESTAMP DEFAULT 0, `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY(`user_id`,`aaa_code`) ) PARTITION BY RANGE (UNIX_TIMESTAMP(created_at)) […]

Read full article | コメントは受け付けていません。

subprocess check_output , check kyototycoon

2月 8th, 2013

http://docs.python.org/2/library/subprocess.html#replacing-older-functions-with-the-subprocess-module nagios用のスクリプト pythonからktremotemgrを呼んで状態を確認する 2.6なのでcheck_outputが使えなかった http://docs.python.org/2.6/library/subprocess.html#module-subprocess popenのところだけ from subprocess import Popen,PIPE # 略 p = Popen(["ktremotemgr","report","-host",options.hostname,"-port",str(options.port),"-tout","2"], stdout=PIPE)  output = p.communicate()[0]  if re.search(r’db_total_count’, output ):    m = re.search(r’db_total_count: ([0-9]*)’, output )    count = m.group(1)    m = re.search(r’db_total_size: ([0-9]*)’, output )    size = m.group(1)    print “OK: %s %s:%d count:%s size:%s” % (service, options.hostname, […]

Read full article | コメントは受け付けていません。

mysql-python mysqldb

2月 8th, 2013

http://mysql-python.sourceforge.net/ http://sourceforge.net/projects/mysql-python/ python 2.6 で 2.7は最新、3.xはこれからのようです。 インストール pip-python install MySQL-python Complete output from command python setup.py egg_info: [localhost] out:     The required version of distribute (>=0.6.28) is not available, こんなメッセージが出たので更新してから再度 easy_install -U distribute Successfully installed MySQL-python Cleaning up… === 参考:fabric に設定して fabric update_python_egg install_python_mysql -R all で10数台1回で更新出来ます。 参考:fabric + cuisineで管理 Fabric, Cuisine and Watchdog […]

Read full article | コメントは受け付けていません。

エラーメッセージから対象文字列をコピーして使うのは大事。mysqlにログ出力させてテスト。

12月 9th, 2012

簡単なことで時間を費やすと・・・胃にくる・・・ wordpressのインストールに時間がかかって染ましました。 mysqlのコンフィグに log=…log を追加して、すべてのログをファイルに出力してみます。 wordpressのinstall.phpでログイン出来たけどdatabaseに接続出来ないとエラーが 121209 22:49:26 2 Connect mywordpress@127.0.0.1 on 2 Query SET NAMES utf8 2 Quit しかし、use databaseとかもしていない様子。。set names utf8が怪しい。 あぁ、、、ただの文字打ち間違いでした。。。 database名wordpressをwordperssにしていた感じで、 ログインしてテストして、権限確認してみたり全部sqlでやっていたのですが、 エラーメッセージをコピー&ペーストしなかったのでまったくエラーになりませんでした。 絶対に合っている自信はあるのに、エラーニナルコノ感じ。 胃に穴があく寸前でした。 * エラーメッセージから対象文字列をコピーして使うのは大事。

Read full article | コメントは受け付けていません。

mysqld_multi stop failed + fabricのsudoユーザーでのコマンド回避策

12月 9th, 2012

mysqld_multi stopが出来ない。。。 設定の問題の可能性はあるけど。(設定の問題でした。) start reportは正常でstopだけ出来ないというのは・・・ http://serverfault.com/questions/400182/mysqld-multi-stop-doesnt-seem-to-work 同様の人がいるようなので諦めてmysqladminで mysqladmin -h 127.0.0.1 -P 29016 -uroot -p shutdown と思ったのですが、/etc/my.cnfや~/.my.cnfのmysqld_multiの設定 user passwordのところがおかしかっただけのようで mysqld_multi –defaults-file=/home/sample/app/conf/mysql/wordpress_master.cnf –log=/home/sample/log/my/mysqld-sample-master.log stop で start stop report問題なく出来ました。 fabricから他ユーザーで実行したときの挙動がいまいちだったので。いろいろ試した。 mysqlはanyusernameというユーザー名の人が実行している場合。 fab -H localhost -p pass stop_mysql local(‘sudo -u anyusername mysqld_multi –defaults-file=%s –verbose –user=root –log=%s %s’ % ( mycnf, errorlog, cmd )) とりあえず、これでstopまで問題なく行けたが。 with settings(sudo_user=”anyusername”): sudo(‘mysqld_multi –defaults-file=%s –verbose […]

Read full article | コメントは受け付けていません。

mysqlの日時,date,datetime,timestampの違い。

12月 7th, 2012

DATE, DATETIME, TIMESTAMPの違い。 http://dev.mysql.com/doc/refman/5.5/en/datetime.html The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in ‘YYYY-MM-DD’ format. The supported range is ‘1000-01-01′ to ‘9999-12-31′. The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values […]

Read full article | コメントは受け付けていません。

mysql 5.5 innodb

12月 7th, 2012

mysql 5.1だと innodb pluginを入れないと行けないそうでが、5.5はinnodb標準だそうで。 いくつか記事を読むとパフォーマンスが違うそうで。 デフォルトのmy-huge.cnfは一カ所しか変わっていないようで $ diff /usr/share/mysql/my-huge.cnf ./my-huge.cnf 28c28 < skip-external-locking --- > skip-locking http://dev.mysql.com/doc/refman/5.1/en/replacing-builtin-innodb.html http://dev.mysql.com/doc/refman/5.5/en/innodb-configuration.html http://thinkit.co.jp/story/2011/11/25/2343?page=0,1 http://www.atmarkit.co.jp/fdb/rensai/dbwatch2011/dbwatch201101_01.html 5.1でinnodb pluginを利用する場合はこちらが参考になりそうです。 http://d.hatena.ne.jp/sh2/20110720 hdd ssd比較 http://d.hatena.ne.jp/sh2/20090907

Read full article | コメントは受け付けていません。

kyototycoon lua 複数取得を少し変えてみた。

12月 3rd, 2012

フラグデータを値データを分けて保管するためにluaを利用していたのですが getの時 function get_player( inmap, outmap )  local key = inmap.key  local dbid = tonumber(inmap.db)  local playerdb = kt.dbs[dbid];  local item = playerdb:get(key)  if item then    local ix = kt.mapload(item)    for k,v in pairs(ix) do      outmap[k]=v    end  end  return kt.RVSUCCESS end これで ktremotemgr script -port 30132 get_player key test db […]

Read full article | コメントは受け付けていません。