Permalink
Browse files

Handler 'Remote Administration' has been enhancement to support

Front-Line cache objects expiration, so has been cherokee-tweak.

git-svn-id: svn://cherokee-project.com/cherokee/trunk@6598 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent 36d2edb commit 44b8a3d63b3e65c1d548b0b8f6673909c7366b2c @alobbs alobbs committed May 7, 2011
View
@@ -188,16 +188,16 @@ def __init__ (self, refresh, right_box, vsrv_num):
comment.append ("no %s"%(e))
if CTK.cfg.get_val ('vserver!%s!rule!%s!flcache'%(vsrv_num, r)) == "allow":
- comment.append ('cache')
+ comment.append ('Cache')
if CTK.cfg.get_val ('vserver!%s!rule!%s!timeout' %(vsrv_num, r)):
- comment.append ('timeout')
+ comment.append ('Timeout')
if CTK.cfg.get_val ('vserver!%s!rule!%s!rate' %(vsrv_num, r)):
- comment.append ('traffic')
+ comment.append ('Traffic')
if int (CTK.cfg.get_val ('vserver!%s!rule!%s!no_log'%(vsrv_num, r), "0")) > 0:
- comment.append ('no log')
+ comment.append ('No log')
# List entry
row_id = '%s_%s' %(r, vsrv_num)
View
@@ -37,6 +37,7 @@
('delete', 'DELETE'),
('trace', 'TRACE'),
('connect', 'CONNECT'),
+ ('purge', 'PURGE'),
('copy', 'COPY'),
('lock', 'LOCK'),
('mkcol', 'MKCOL'),
@@ -95,7 +96,7 @@ def __init__ (self, key, **kwargs):
CTK.cfg ['%s!method'%(key)] = METHODS[idx:][0][0]
table = CTK.PropsTable()
- table.Add (_('Method'), CTK.ComboCfg('%s!method'%(key), METHODS[idx:]), _(NOTE_METHOD))
+ table.Add (_('Method'), CTK.ComboCfg('%s!method'%(key), METHODS[idx:], ({}, {'class': 'noauto'})[is_new]), _(NOTE_METHOD))
submit = CTK.Submitter (URL_APPLY)
submit += CTK.Hidden ('key', key)
@@ -105,7 +106,7 @@ def __init__ (self, key, **kwargs):
def GetName (self):
method = CTK.cfg.get_val ('%s!method' %(self.key), '')
- return "%s %s" % (_('Method'), method)
+ return "%s %s" % (_('Method'), method.upper())
CTK.publish (URL_APPLY, commit, method="POST")
View
@@ -390,6 +390,38 @@ cherokee_avl_flcache_get (cherokee_avl_flcache_t *avl,
static ret_t
+del_list_of_entries (cherokee_avl_flcache_t *avl,
+ cherokee_list_t *to_delete)
+{
+ ret_t ret;
+ cherokee_list_t *i, *j;
+ cherokee_boolean_t error = false;
+
+ list_for_each_safe (i, j, to_delete) {
+ cherokee_avl_flcache_node_t *node = list_entry (i, cherokee_avl_flcache_node_t, to_del);
+
+ if (node->ref_count > 0)
+ continue;
+
+ TRACE (ENTRIES, "Removing Front-line cache file: '%s'\n", node->file.buf ? node->file.buf : "");
+
+ /* Delete local file */
+ if (! cherokee_buffer_is_empty (&node->file)) {
+ cherokee_unlink (node->file.buf);
+ }
+
+ /* Delete try from the AVL tree*/
+ ret = cherokee_avl_generic_del (AVL_GENERIC(avl), AVL_GENERIC_NODE(node), NULL);
+ if (unlikely (ret != ret_ok)) {
+ error = true;
+ }
+ }
+
+ return (error) ? ret_error : ret_ok;
+}
+
+
+static ret_t
cleanup_while_func (cherokee_avl_generic_node_t *node_generic, void *value, void *param)
{
cherokee_list_t *to_delete = LIST(param);
@@ -407,11 +439,10 @@ cleanup_while_func (cherokee_avl_generic_node_t *node_generic, void *value, void
return ret_ok;
}
+
ret_t
cherokee_avl_flcache_cleanup (cherokee_avl_flcache_t *avl)
{
- ret_t ret;
- cherokee_list_t *i, *j;
cherokee_list_t to_delete = LIST_HEAD_INIT(to_delete);
CHEROKEE_RWLOCK_WRITER (&avl->base_rwlock);
@@ -422,22 +453,7 @@ cherokee_avl_flcache_cleanup (cherokee_avl_flcache_t *avl)
/* Delete entries
*/
- list_for_each_safe (i, j, &to_delete) {
- cherokee_avl_flcache_node_t *node = list_entry (i, cherokee_avl_flcache_node_t, to_del);
-
- TRACE (ENTRIES, "Removing Front-line cache file: '%s'\n", node->file.buf ? node->file.buf : "");
-
- /* Delete local file */
- if (! cherokee_buffer_is_empty (&node->file)) {
- cherokee_unlink (node->file.buf);
- }
-
- /* Delete try from the AVL tree*/
- ret = cherokee_avl_generic_del (AVL_GENERIC(avl), AVL_GENERIC_NODE(node), NULL);
- if (unlikely (ret != ret_ok)) {
- ; // TO DO
- }
- }
+ del_list_of_entries (avl, &to_delete);
CHEROKEE_RWLOCK_UNLOCK (&avl->base_rwlock);
@@ -459,3 +475,60 @@ cherokee_avl_flcache_del (cherokee_avl_flcache_t *avl,
return ret;
}
+
+
+static ret_t
+purge_while_func (cherokee_avl_generic_node_t *node_generic, void *value, void **params)
+{
+ cherokee_avl_flcache_node_t *node = AVL_FLCACHE_NODE(node_generic);
+ cherokee_buffer_t *path = (cherokee_buffer_t *) (params[0]);
+ cuint_t *purged_num = (cuint_t *) (params[1]);
+ cherokee_list_t *to_delete = (cherokee_list_t *) (params[2]);
+
+ UNUSED(value);
+
+ /* Expire entries that match the path
+ */
+ if (cherokee_buffer_cmp_buf (path, &node->request) == 0) {
+ *purged_num += 1;
+
+ /* Expire the object
+ */
+ node->valid_until = 0;
+
+ /* Whenever possible, remove it from the cache
+ */
+ cherokee_list_add (&node->to_del, to_delete);
+ }
+
+ return ret_ok;
+}
+
+ret_t
+cherokee_avl_flcache_purge_path (cherokee_avl_flcache_t *avl,
+ cherokee_buffer_t *path)
+{
+ ret_t ret;
+ cuint_t purged_num = 0;
+ cherokee_list_t to_delete = LIST_HEAD_INIT(to_delete);
+ void *params[] = {path, &purged_num, &to_delete};
+
+ /* FIXME: O(N) function. This is clearly sub-optimal.
+ */
+ CHEROKEE_RWLOCK_WRITER (&avl->base_rwlock);
+
+ ret = cherokee_avl_generic_while (AVL_GENERIC(avl),
+ (cherokee_avl_generic_while_func_t) purge_while_func,
+ params, NULL, NULL);
+
+ del_list_of_entries (avl, &to_delete);
+ TRACE (ENTRIES, "Purging '%s' - %d objects were expired\n", path->buf, purged_num);
+
+ CHEROKEE_RWLOCK_UNLOCK (&avl->base_rwlock);
+
+ if (purged_num == 0) {
+ return ret_not_found;
+ }
+
+ return ret;
+}
View
@@ -81,16 +81,19 @@ ret_t cherokee_avl_flcache_init (cherokee_avl_flcache_t *avl);
ret_t cherokee_avl_flcache_mrproper (cherokee_avl_flcache_t *avl, cherokee_func_free_t free_value);
ret_t cherokee_avl_flcache_cleanup (cherokee_avl_flcache_t *avl);
-ret_t cherokee_avl_flcache_add (cherokee_avl_flcache_t *avl,
- cherokee_connection_t *conn,
- cherokee_avl_flcache_node_t **node);
+ret_t cherokee_avl_flcache_add (cherokee_avl_flcache_t *avl,
+ cherokee_connection_t *conn,
+ cherokee_avl_flcache_node_t **node);
-ret_t cherokee_avl_flcache_get (cherokee_avl_flcache_t *avl,
- cherokee_connection_t *conn,
- cherokee_avl_flcache_node_t **node);
+ret_t cherokee_avl_flcache_get (cherokee_avl_flcache_t *avl,
+ cherokee_connection_t *conn,
+ cherokee_avl_flcache_node_t **node);
-ret_t cherokee_avl_flcache_del (cherokee_avl_flcache_t *avl,
- cherokee_avl_flcache_node_t *node);
+ret_t cherokee_avl_flcache_del (cherokee_avl_flcache_t *avl,
+ cherokee_avl_flcache_node_t *node);
+
+ret_t cherokee_avl_flcache_purge_path (cherokee_avl_flcache_t *avl,
+ cherokee_buffer_t *path);
CHEROKEE_END_DECLS
View
@@ -41,6 +41,7 @@ APP_COPY_NOTICE =
USAGE = \
"Usage:\n" \
" cherokee-tweak [options] URL info \n" \
+ " cherokee-tweak [options] URL purge \n" \
" cherokee-tweak [options] URL sources \n" \
" cherokee-tweak [options] URL kill-source ID \n" \
" cherokee-tweak [options] URL logrotate PATH \n" \
@@ -50,7 +51,8 @@ USAGE = \
" trace Manipulates the tracing mechanism\n" \
" logrotate Rotates a local log file\n" \
" sources Prints a list of the info. sources\n" \
- " kill-source Kill a remote information source\n\n" \
+ " kill-source Kill a remote information source\n" \
+ " purge Purge objects from the cache\n\n" \
" Parameters:\n" \
" -h, --help Print this help\n" \
" -V, --version Print version and exit\n\n" \
@@ -68,7 +70,6 @@ log = None
trace = None
ksource = None
-
def parse_args():
global command, url
global user, password
@@ -125,6 +126,8 @@ def parse_args():
# Check command
if command == 'info':
None
+ elif command == 'purge':
+ None
elif command == 'trace':
trace = sys.argv[argn]
argn += 1
@@ -141,11 +144,7 @@ def parse_args():
raise SystemExit
-def request (commands):
- tmp = url + '/py'
- url_py = tmp[:7] + tmp[7:].replace('//','/')
- post_info = "%s\n" %('\n'.join(commands))
-
+def http_request (path, post_info=None, method=None):
# Authtentication
if user or password:
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
@@ -154,17 +153,35 @@ def request (commands):
authhandler = urllib2.HTTPBasicAuthHandler (passman)
opener = urllib2.build_opener (authhandler)
urllib2.install_opener (opener)
+ else:
+ opener = urllib2.build_opener (urllib2.HTTPHandler)
# Request
try:
- conn = urllib2.urlopen (url_py, post_info)
+ request = urllib2.Request (path, post_info)
+ if method:
+ request.get_method = lambda: method
+
+ conn = opener.open (request)
+
+ ## conn = urllib2.urlopen (url_py, post_info)
except urllib2.HTTPError, e:
if e.code == 401:
print >> sys.stderr, "Error in Authentication"
raise SystemExit
raise
+
return conn.read()
+
+def request (commands):
+ tmp = url + '/py'
+ url_py = tmp[:7] + tmp[7:].replace('//','/')
+ post_info = "%s\n" %('\n'.join(commands))
+
+ return http_request (url_py, post_info)
+
+
def eval_safe (txt):
try:
return eval(txt)
@@ -326,12 +343,27 @@ def do_logrotate():
assert not backup[0]['backup_mode'], "Couldn't unset backup mode"
+#
+# Purge from Cache
+#
+
+def do_purge():
+ try:
+ response_py = http_request (url, method="PURGE")
+ except urllib2.HTTPError, e:
+ if e.code == 404:
+ print >> sys.stderr, "Object not found in the cache"
+ sys.exit(1)
+ raise
+
def main():
parse_args()
if command == 'info':
print_info()
+ elif command == 'purge':
+ do_purge()
elif command == 'sources':
print_sources()
elif command == 'kill-source':
View
@@ -208,6 +208,14 @@ cherokee_flcache_req_is_storable (cherokee_flcache_t *flcache,
}
+ret_t
+cherokee_flcache_purge_path (cherokee_flcache_t *flcache,
+ cherokee_buffer_t *path)
+{
+ return cherokee_avl_flcache_purge_path (&flcache->request_map, path);
+}
+
+
/* Front-line cache connection
*/
View
@@ -86,6 +86,7 @@ ret_t cherokee_flcache_req_get_cached (cherokee_flcache_t *flcache, cherokee_co
ret_t cherokee_flcache_req_is_storable (cherokee_flcache_t *flcache, cherokee_connection_t *conn);
ret_t cherokee_flcache_req_set_store (cherokee_flcache_t *flcache, cherokee_connection_t *conn);
ret_t cherokee_flcache_del_entry (cherokee_flcache_t *flcache, cherokee_avl_flcache_node_t *entry);
+ret_t cherokee_flcache_purge_path (cherokee_flcache_t *flcache, cherokee_buffer_t *path);
/* Front-line cache connection
*/
Oops, something went wrong.

0 comments on commit 44b8a3d

Please sign in to comment.