Anshu: To create a background thread, you need to use class
drizzled::plugin::Daemon

Look at plugin/json_server/json_server.cc (class JsonServer at the
end) for an example.

henrik

On Mon, Apr 2, 2012 at 4:16 PM, Henrik Ingo <henrik.i...@avoinelama.fi> wrote:
> Anshu
>
> You are right. Creating a thread is more correct. I was just trying to
> avoid it since you originally asked for "low-hanging-fruit" bug.
>
> Functionally, ignoring the performance hit, you could do this also
> from the restrict* methods and then you don't need to create your own
> thread.
>
> henrik
>
> On Mon, Apr 2, 2012 at 3:45 PM, Anshu Kumar <ansharyan...@gmail.com> wrote:
>> Hey Henrik,
>> What I was thinking is we can have a system like this. When autoreload
>> variable is set to true, we can create a thread which will check either by
>> inotify or stat() that the corresponding regex policy file is changed or
>> not. And it of does then only reload the file. This is just like creating a
>> handler for change in policy file. The performance will be better than
>> polling for a min and reloading the policy file.
>> The implementation is actually the same in this, and the way you suggested
>> by Policy::restrict methods. So did you want to say that when checking for
>> regex policy rights (if access is allowed or denied), we can check if file
>> needs to be refreshed?
>>
>> On Mon, Apr 2, 2012 at 6:02 PM, Henrik Ingo <henrik.i...@avoinelama.fi>
>> wrote:
>>>
>>> Anshu
>>>
>>> Actually, now that I re-read this, I don't know if it was a smart idea
>>> and maybe there needs to be a thread that does the polling, but my
>>> original idea was that you could reload the file during an
>>> authorization request. So basically when any of the
>>> Polixy::restrict... methods are called, you would first check if the
>>> file needs to be refreshed and then re-read it (or not). This way you
>>> don't need to have a loop or do any polling or such.
>>>
>>> This approach is not good because it would introduce a performance hit
>>> into random requests every N seconds. But you could still do it this
>>> way as a proof of concept, then we could work on making it a
>>> background thread later.
>>>
>>> henrik
>>>
>>> On Mon, Apr 2, 2012 at 2:51 PM, Anshu Kumar <ansharyan...@gmail.com>
>>> wrote:
>>> > Hey Guys,
>>> > I have tried to implement this dynamic thing to regex_policy plugin.
>>> > In reference to my talk with Henrik yesterday, we discussed that there
>>> > could
>>> > be a autoreload variable, and when made true it will continuously poll
>>> > for
>>> > changes in default regex policy file. And it it is made false, it will
>>> > stop
>>> > polling, checking for modifications. Sticking to the discussion, the
>>> > code I
>>> > wrote is
>>> >
>>> > void autoReload_Regex_Policy(Session *, sql_var_t)
>>> > {
>>> >         if(policy->sysvar_autoreload)
>>> >         {
>>> >                 while(1)
>>> >                 {
>>> >                         if (not policy->loadFile())
>>> >                           {
>>> >                             errmsg_printf(error::ERROR, _("Could not
>>> > load
>>> > regex policy file: %s\n"),
>>> >                                           (policy ?
>>> > policy->getError().str().c_str() : _("Unknown")));
>>> >                             return;
>>> >                           }
>>> >                         sleep(60);
>>> >                         if(!policy->sysvar_autoreload)
>>> >                                 break;
>>> >                 }
>>> >         }
>>> >         else
>>> >         {
>>> >         }
>>> > }
>>> > This function handles the case when you change the value of autoreload
>>> > from
>>> > drizzle client. The problem is as the function is using sleep
>>> > recursively,
>>> > when trying to change autoreload value by "SET GLOBAL", the client
>>> > hangs.
>>> > This is obviously due to function recursive structure. Initially, I
>>> > thought
>>> > that it would change the variable and then polls.
>>> >
>>> > Now, coming to the discussion earlier in this mail, even if I create a
>>> > pthread from this function which will check for modification using
>>> > stat() or
>>> > inotify(), this function won't exit untill its thread stop working. And
>>> > as
>>> > thread will continuously polls for changes, it wont exit.
>>> >
>>> > Is there any solution for this scenario, except adding the refresh
>>> > command
>>> > for refreshing the policy file?
>>> >
>>> >
>>> > On Fri, Mar 30, 2012 at 10:34 PM, Clint Byrum <cl...@fewbar.com> wrote:
>>> >>
>>> >> Excerpts from Henrik Ingo's message of Thu Mar 29 21:16:26 -0700 2012:
>>> >> > Daniel:
>>> >> >
>>> >> > Have you thought about authorization for this? I mean we wouldn't
>>> >> > want
>>> >> > any old logged in user to be able to
>>> >> >
>>> >> > SET GLOBAL auth_file.users=/home/hingo/igivemyselfrootpowers.users
>>> >> >
>>> >> > (Making the plugin reload the existing file will be helpful. But it
>>> >> > might not be a good idea to allow to change that value.)
>>> >> >
>>> >>
>>> >> Agreed. I'd like to see plugins like auth_file and regex_policy given
>>> >> a generic way to "watch" their files. There are a number of ways to do
>>> >> this, but I don't think each plugin should implement its own method.
>>> >>
>>> >> Thoughts I've had on this:
>>> >>
>>> >> * A thread which uses either inotify  or falls back to polling
>>> >> with stat(), and whenever there is a change, calls any registered code
>>> >> to update that file's effect.
>>> >>
>>> >> * An admin command like  REFRESH '/etc/drizzle/regex.policy' which does
>>> >> the same thing as the thread without the inotify/polling.
>>> >>
>>> >> * Cache the stat() call on the file and periodically expire the cache
>>> >> and refresh the contents if stat() indicates that it has changed.
>>> >>
>>> >> _______________________________________________
>>> >> Mailing list: https://launchpad.net/~drizzle-discuss
>>> >> Post to     : drizzle-discuss@lists.launchpad.net
>>> >> Unsubscribe : https://launchpad.net/~drizzle-discuss
>>> >> More help   : https://help.launchpad.net/ListHelp
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Regards,
>>> > Ansh
>>> >
>>> >
>>> > _______________________________________________
>>> > Mailing list: https://launchpad.net/~drizzle-discuss
>>> > Post to     : drizzle-discuss@lists.launchpad.net
>>> > Unsubscribe : https://launchpad.net/~drizzle-discuss
>>> > More help   : https://help.launchpad.net/ListHelp
>>> >
>>>
>>>
>>>
>>> --
>>> henrik.i...@avoinelama.fi
>>> +358-40-8211286 skype: henrik.ingo irc: hingo
>>> www.openlife.cc
>>>
>>> My LinkedIn profile: http://www.linkedin.com/profile/view?id=9522559
>>
>>
>>
>>
>> --
>> Regards,
>> Ansh
>>
>
>
>
> --
> henrik.i...@avoinelama.fi
> +358-40-8211286 skype: henrik.ingo irc: hingo
> www.openlife.cc
>
> My LinkedIn profile: http://www.linkedin.com/profile/view?id=9522559



-- 
henrik.i...@avoinelama.fi
+358-40-8211286 skype: henrik.ingo irc: hingo
www.openlife.cc

My LinkedIn profile: http://www.linkedin.com/profile/view?id=9522559

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : drizzle-discuss@lists.launchpad.net
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to