embedded/compact not overwriting file

8 views
Skip to first unread message

Tim Robinson

unread,
Jul 19, 2010, 8:28:54 PM7/19/10
to FleetDB
As a FYI, for whatever reason whenever I run compact, it creates
the .tmp file, but does not move it, leaving the .tmp open
(continually appending to it).

It's probably because the writer is still open. Not sure if anyone
else can verify the problem.

At any rate, I thought I'd also mention for others, there's an easy
work around which seem to do the trick for me:

(let [db-file "data/demo.dbf"
db-atom (embedded/load-persistent db-file)]
(embedded/compact db-atom)
(file/mv (str db-file ".tmp") db-file) ; just put mv operation
outside the compact function.
(embedded/close db-atom)))

You could also remove the mv operation from the embedded/compact
source since it seems not to work.

Regards,
Tim

Mark McGranaghan

unread,
Jul 19, 2010, 8:51:22 PM7/19/10
to fle...@googlegroups.com
Hi Tim,

Compaction works for me (see below); what FleetDB version are you
using and on what platform?

$ fleetdb-server -f data.fdb &
$ echo '["insert", "data", {"id": 1}]' | nc localhost 3400
$ echo '["insert", "data", {"id": 2}]' | nc localhost 3400
$ cat data.fdb
["insert","data",{"id":1}]
["insert","data",{"id":2}]
$ echo '["compact"]' | nc localhost 3400
$ cat data.fdb
["insert","data",[{"id":2},{"id":1}]]
$ ls
data.fdb

- Mark

Tim Robinson

unread,
Jul 19, 2010, 9:38:32 PM7/19/10
to FleetDB
I use len:

:dependencies
[[org.clojure/clojure "1.2.0-beta1"]
[org.clojure/clojure-contrib "1.2.0-beta1"]
[clj-stacktrace "0.1.2"]
[net.sf.jopt-simple/jopt-simple "3.2"]
[clj-json "0.2.0"]
[ring/ring-core "0.2.5"]
[ring/ring-jetty-adapter "0.2.5"]]
:dev-dependencies [[org.clojars.mmcgrana/lein-clojars "0.5.0"]
[org.clojars.mmcgrana/lein-javac "0.1.0"]
[clj-unit "0.1.0"]]

+ I am using FleetDB 0.2.0-RC2
* I have FleetDB in /src. (Clojars had not been updated so I
configured locally - everything else works fine - so I don't think
this is a problem??)
* I didn't do the last update from RC2 - it appeared there was no
diff when I looked.

Machine System Version: Mac OS X 10.6.4 (10F569)

I guess that's a lot of variables.

Tim

Clojure 1.2.0-beta1 seems pretty stable. Your latest change log
indicates you had made changes to be 1.20 friendly.

Tim Robinson

unread,
Jul 19, 2010, 9:45:18 PM7/19/10
to FleetDB
Sorry that was Ring where I saw Stuarts commit log comments on
"Clojure 1.2 agnostic" not FleetDB.
I'm reading too many of your projects :)

Tim Robinson

unread,
Jul 19, 2010, 9:58:50 PM7/19/10
to FleetDB
Also,

I noticed you tried using FleetDB over the wire.

I'm loading FleetDB source and calling via directly from the repl.
I am not sure if that's a problem, but I noted from a previous post
that was ok.

Tim

Mark McGranaghan

unread,
Jul 20, 2010, 12:37:46 PM7/20/10
to fle...@googlegroups.com
Hi Tim,

A few things:

You rightly pointed out that I hadn't pushed either 0.2.0-RC2 or 0.2.0
to Clojars - I've now done that.

Your problem brings up the issue of Clojure 1.2 compatibility. I
didn't have Clojure 1.2 compatibility as a goal for the 0.2 series. At
the source level 0.2 may be Clojure 1.2 compatible, but unfortunately
the jars have Clojure 1.1 compiled code that does not seem to be
accepted by Clojure 1.2 runtimes. The issue of compiled Clojure code
in jars is a significant one that I'll need to return to later.

That said, if you are just using FleetDB 0.2.0-RC2 or 0.2.0 from
source at least the following example should work fine:

$ cat embedded.clj
(require '[fleetdb.embedded :as emb])

(let [dba (emb/init-persistent "demo.fdb")]
(emb/query dba ["insert" "data" {"id" 1}])
(emb/query dba ["insert" "data" {"id" 2}])
(emb/compact dba)
(Thread/sleep 100)
(emb/close dba))

$ clj embedded.clj


$ cat data.fdb
["insert","data",[{"id":2},{"id":1}]]

This works for me locally, even with Clojure 1.2; do you see something
different?

- Mark

Tim Robinson

unread,
Jul 20, 2010, 6:57:32 PM7/20/10
to FleetDB
I think you meant load-persistent, but yes the following appears to
fix the problem.

(let [db-file (str datadir* dbf)
db-atom (embedded/load-persistent db-file)
rc (embedded/compact db-atom)]
(Thread/sleep 100)
(embedded/close db-atom)
rc)

Thanks for you help!

PS, At least one good thing is that I have been testing out quite a
bit of the functionality
with Clojure 1.2-beta. Hopefully this proves you don't have to worry
to much about switching
over.

Tim

On Jul 20, 10:37 am, Mark McGranaghan <mmcgr...@gmail.com> wrote:
> Hi Tim,
>
Reply all
Reply to author
Forward
0 new messages